Skip to content

Commit 27372c8

Browse files
authored
Split pytest run into 3 parts to improve parallelization (#5764)
This can speed up test runtimes by 15% to 50%. Also this makes it easier to rerun only part of the test suite. Fixes #5755. The same issue may also affect travis and appveyor builds, and this doesn't address them.
1 parent e170f6b commit 27372c8

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

runtests.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,53 @@
1414
else:
1515
python_name = 'python3'
1616

17+
# Slow test suites
18+
CMDLINE = 'PythonCmdline'
19+
SAMPLES = 'SamplesSuite'
20+
TYPESHED = 'TypeshedSuite'
21+
PEP561 = 'TestPEP561'
22+
EVALUATION = 'PythonEvaluation'
23+
24+
ALL_NON_FAST = [CMDLINE, SAMPLES, TYPESHED, PEP561, EVALUATION]
25+
26+
# We split the pytest run into three parts to improve test
27+
# parallelization. Each run should have tests that each take a roughly similiar
28+
# time to run.
1729
cmds = {
30+
# Self type check
1831
'self': python_name + ' -m mypy --config-file mypy_self_check.ini -p mypy',
32+
# Lint
1933
'lint': 'flake8 -j0',
20-
'pytest': 'pytest'
34+
# Fast test cases only (this is the bulk of the test suite)
35+
'pytest-fast': 'pytest -k "not (%s)"' % ' or '.join(ALL_NON_FAST),
36+
# Test cases that invoke mypy (with small inputs)
37+
'pytest-cmdline': 'pytest -k "%s"' % ' or '.join([CMDLINE, EVALUATION]),
38+
# Test cases that may take seconds to run each
39+
'pytest-slow': 'pytest -k "%s"' % ' or '.join([SAMPLES, TYPESHED, PEP561]),
2140
}
2241

42+
# Stop run immediately if these commands fail
43+
FAST_FAIL = ['self', 'lint']
44+
45+
assert all(cmd in cmds for cmd in FAST_FAIL)
46+
2347
if not set(args).issubset(cmds):
2448
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
2549
exit(1)
2650

2751
if not args:
2852
args = list(cmds)
2953

54+
status = 0
55+
3056
for arg in args:
3157
cmd = cmds[arg]
32-
print('$', cmd)
58+
print('run %s: %s' % (arg, cmd))
3359
res = (system(cmd) & 0x7F00) >> 8
3460
if res:
35-
exit(res)
61+
print('\nFAILED: %s' % arg)
62+
status = res
63+
if arg in FAST_FAIL:
64+
exit(status)
65+
66+
exit(status)

0 commit comments

Comments
 (0)