Skip to content

Commit 89e259f

Browse files
authored
Make runtests.py skip some slow mypyc tests by default (python#8199)
The skipped mypyc run tests are very slow and I believe that they only rarely fail for changes that don't touch mypyc. The skipped tests can be run via runtests.py mypyc-extra. Also explain running tests in some more detail in the the docs.
1 parent cdd91ba commit 89e259f

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Mypy can be integrated into popular IDEs:
114114
* Using [Syntastic](https://github.com/vim-syntastic/syntastic): in `~/.vimrc` add
115115
`let g:syntastic_python_checkers=['mypy']`
116116
* Using [ALE](https://github.com/dense-analysis/ale): should be enabled by default when `mypy` is installed,
117-
or can be explicitly enabled by adding `let b:ale_linters = ['mypy']` in `~/vim/ftplugin/python.vim`
117+
or can be explicitly enabled by adding `let b:ale_linters = ['mypy']` in `~/vim/ftplugin/python.vim`
118118
* Emacs: using [Flycheck](https://github.com/flycheck/) and [Flycheck-mypy](https://github.com/lbolla/emacs-flycheck-mypy)
119119
* Sublime Text: [SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
120120
* Atom: [linter-mypy](https://atom.io/packages/linter-mypy)
@@ -237,7 +237,8 @@ The basic way to run tests:
237237
$ python2 -m pip install -U typing
238238
$ ./runtests.py
239239

240-
For more on the tests, see [Test README.md](test-data/unit/README.md)
240+
For more on the tests, such as how to write tests and how to control
241+
which tests to run, see [Test README.md](test-data/unit/README.md).
241242

242243

243244
Development status

runtests.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
MYPYC_COMMAND_LINE,
4545
ERROR_STREAM]
4646

47+
48+
# These must be enabled by explicitly including 'mypyc-extra' on the command line.
49+
MYPYC_OPT_IN = [MYPYC_RUN,
50+
MYPYC_RUN_MULTI]
51+
4752
# We split the pytest run into three parts to improve test
4853
# parallelization. Each run should have tests that each take a roughly similar
4954
# time to run.
@@ -65,16 +70,19 @@
6570
TYPESHED,
6671
PEP561,
6772
DAEMON,
68-
MYPYC_RUN,
69-
MYPYC_RUN_MULTI,
7073
MYPYC_EXTERNAL,
7174
MYPYC_COMMAND_LINE,
7275
ERROR_STREAM]),
76+
# Mypyc tests that aren't run by default, since they are slow and rarely
77+
# fail for commits that don't touch mypyc
78+
'mypyc-extra': 'pytest -k "%s"' % ' or '.join(MYPYC_OPT_IN),
7379
}
7480

7581
# Stop run immediately if these commands fail
7682
FAST_FAIL = ['self', 'lint']
7783

84+
DEFAULT_COMMANDS = [cmd for cmd in cmds if cmd != 'mypyc-extra']
85+
7886
assert all(cmd in cmds for cmd in FAST_FAIL)
7987

8088

@@ -117,10 +125,12 @@ def main() -> None:
117125

118126
if not set(args).issubset(cmds):
119127
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
128+
print()
129+
print('Run the given tests. If given no arguments, run everything except mypyc-extra.')
120130
exit(1)
121131

122132
if not args:
123-
args = list(cmds)
133+
args = DEFAULT_COMMANDS[:]
124134

125135
status = 0
126136

test-data/unit/README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Add the test in this format anywhere in the file:
3030
with text "abc..."
3131
- note a space after `E:` and `flags:`
3232
- `# E:12` adds column number to the expected error
33-
- use `\` to escape the `#` character and indicate that the rest of the line is part of
33+
- use `\` to escape the `#` character and indicate that the rest of the line is part of
3434
the error message
3535
- repeating `# E: ` several times in one line indicates multiple expected errors in one line
3636
- `W: ...` and `N: ...` works exactly like `E:`, but report a warning and a note respectively
@@ -88,29 +88,32 @@ module:
8888

8989
$ python2 -m pip install -U typing
9090

91-
The unit test suites are driven by the `pytest` framework. To run all tests,
91+
The unit test suites are driven by the `pytest` framework. To run all mypy tests,
9292
run `pytest` in the mypy repository:
9393

94-
$ pytest
95-
96-
Note that some tests will be disabled for older python versions.
94+
$ pytest mypy
9795

9896
This will run all tests, including integration and regression tests,
99-
and will type check mypy and verify that all stubs are valid. This may
100-
take several minutes to run, so you don't want to use this all the time
101-
while doing development.
97+
and will verify that all stubs are valid. This may take several minutes to run,
98+
so you don't want to use this all the time while doing development.
10299

103100
Test suites for individual components are in the files `mypy/test/test*.py`.
104101

102+
Note that some tests will be disabled for older python versions.
103+
104+
If you work on mypyc, you will want to also run mypyc tests:
105+
106+
$ pytest mypyc
107+
105108
You can run tests from a specific module directly, a specific suite within a
106-
module, or a test in a suite (even if it's data-driven):
109+
module, or a test in a suite (even if it's data-driven):
107110

108111
$ pytest mypy/test/testdiff.py
109112

110113
$ pytest mypy/test/testsemanal.py::SemAnalTypeInfoSuite
111-
114+
112115
$ pytest -n0 mypy/test/testargs.py::ArgSuite::test_coherence
113-
116+
114117
$ pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::testCallingVariableWithFunctionType
115118

116119
To control which tests are run and how, you can use the `-k` switch:
@@ -144,10 +147,19 @@ To run the linter:
144147

145148
$ flake8
146149

147-
You can also run all of the above tests together with:
150+
You can also run all of the above tests using `runtests.py` (this includes
151+
type checking mypy and linting):
148152

149153
$ python3 runtests.py
150154

155+
By default, this runs everything except some mypyc tests. You can give it
156+
arguments to control what gets run, such as `self` to run mypy on itself:
157+
158+
$ python3 runtests.py self
159+
160+
Run `python3 runtests.py mypyc-extra` to run mypyc tests that are not
161+
enabled by default. This is typically only needed if you work on mypyc.
162+
151163
Many test suites store test case descriptions in text files
152164
(`test-data/unit/*.test`). The module `mypy.test.data` parses these
153165
descriptions.

0 commit comments

Comments
 (0)