Skip to content

Commit 6d91c83

Browse files
committed
Add pytest-xdist 2.0.0 compatibility
Attempt fetching the `workerinput` config node attribute using both the new and the old name. Adjust tox version to test the new xdist with the new pytest only.
1 parent 5736675 commit 6d91c83

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

src/pytest_mypy.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,28 @@ def pytest_addoption(parser):
3333
help="suppresses error messages about imports that cannot be resolved")
3434

3535

36+
XDIST_WORKERINPUT_ATTRIBUTE_NAMES = (
37+
'workerinput',
38+
# xdist < 2.0.0:
39+
'slaveinput',
40+
)
41+
42+
43+
def _get_xdist_workerinput(config_node):
44+
workerinput = None
45+
for attr_name in XDIST_WORKERINPUT_ATTRIBUTE_NAMES:
46+
workerinput = getattr(config_node, attr_name, None)
47+
if workerinput is not None:
48+
break
49+
return workerinput
50+
51+
3652
def _is_master(config):
3753
"""
3854
True if the code running the given pytest.config object is running in
3955
an xdist master node or not running xdist at all.
4056
"""
41-
return not hasattr(config, 'slaveinput')
57+
return _get_xdist_workerinput(config) is None
4258

4359

4460
def pytest_configure(config):
@@ -58,12 +74,12 @@ def pytest_configure(config):
5874
config._mypy_results_path = tmp_f.name
5975

6076
# If xdist is enabled, then the results path should be exposed to
61-
# the slaves so that they know where to read parsed results from.
77+
# the workers so that they know where to read parsed results from.
6278
if config.pluginmanager.getplugin('xdist'):
6379
class _MypyXdistPlugin:
6480
def pytest_configure_node(self, node): # xdist hook
6581
"""Pass config._mypy_results_path to workers."""
66-
node.slaveinput['_mypy_results_path'] = \
82+
_get_xdist_workerinput(node)['_mypy_results_path'] = \
6783
node.config._mypy_results_path
6884
config.pluginmanager.register(_MypyXdistPlugin())
6985

@@ -198,7 +214,7 @@ def _mypy_results(session):
198214
results_path=(
199215
session.config._mypy_results_path
200216
if _is_master(session.config) else
201-
session.config.slaveinput['_mypy_results_path']
217+
_get_xdist_workerinput(session.config)['_mypy_results_path']
202218
),
203219
results_factory=functools.partial(
204220
_mypy_results_factory,

tox.ini

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,84 @@ python =
2020
[testenv]
2121
deps =
2222
pytest3.5: pytest ~= 3.5.0
23+
pytest3.5: pytest-cov ~= 2.5.1
24+
pytest3.5: pytest-randomly ~= 2.1.1
2325
pytest3.5: pytest-xdist < 1.19.0
2426
pytest3.6: pytest ~= 3.6.0
27+
pytest3.6: pytest-cov ~= 2.5.1
28+
pytest3.6: pytest-randomly ~= 2.1.1
2529
pytest3.6: pytest-xdist < 1.28.0
2630
pytest3.7: pytest ~= 3.7.0
31+
pytest3.7: pytest-cov ~= 2.5.1
32+
pytest3.7: pytest-randomly ~= 2.1.1
2733
pytest3.7: pytest-xdist < 1.28.0
2834
pytest3.8: pytest ~= 3.8.0
35+
pytest3.8: pytest-cov ~= 2.5.1
36+
pytest3.8: pytest-randomly ~= 2.1.1
2937
pytest3.8: pytest-xdist < 1.28.0
3038
pytest3.9: pytest ~= 3.9.0
39+
pytest3.9: pytest-cov ~= 2.5.1
40+
pytest3.9: pytest-randomly ~= 2.1.1
3141
pytest3.9: pytest-xdist < 1.28.0
3242
pytest3.10: pytest ~= 3.10.0
43+
pytest3.10: pytest-cov ~= 2.5.1
44+
pytest3.10: pytest-randomly ~= 2.1.1
3345
pytest3.10: pytest-xdist < 1.28.0
3446
pytest3.x: pytest ~= 3.5
47+
pytest3.x: pytest-cov ~= 2.5.1
48+
pytest3.x: pytest-randomly ~= 2.1.1
3549
pytest3.x: pytest-xdist < 1.28.0
3650
pytest4.0: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
3751
pytest4.0: pytest ~= 4.0.0
52+
pytest4.0: pytest-cov ~= 2.5.1
53+
pytest4.0: pytest-randomly ~= 2.1.1
3854
pytest4.0: pytest-xdist < 1.28.0
3955
pytest4.1: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
4056
pytest4.1: pytest ~= 4.1.0
57+
pytest4.1: pytest-cov ~= 2.5.1
58+
pytest4.1: pytest-randomly ~= 2.1.1
4159
pytest4.1: pytest-xdist < 1.28.0
4260
pytest4.2: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
61+
pytest4.2: pytest-cov ~= 2.5.1
62+
pytest4.2: pytest-randomly ~= 2.1.1
4363
pytest4.2: pytest ~= 4.2.0
4464
pytest4.2: pytest-xdist < 1.28.0
4565
pytest4.3: pytest ~= 4.3.0
66+
pytest4.3: pytest-cov ~= 2.5.1
67+
pytest4.3: pytest-randomly ~= 2.1.1
4668
pytest4.3: pytest-xdist < 1.28.0
4769
pytest4.4: pytest ~= 4.4.0
70+
pytest4.4: pytest-cov ~= 2.5.1
71+
pytest4.4: pytest-randomly ~= 2.1.1
4872
pytest4.4: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
4973
pytest4.5: pytest ~= 4.5.0
74+
pytest4.5: pytest-cov ~= 2.5.1
75+
pytest4.5: pytest-randomly ~= 2.1.1
5076
pytest4.5: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
5177
pytest4.6: pytest ~= 4.6.0
78+
pytest4.6: pytest-cov ~= 2.5.1
79+
pytest4.6: pytest-randomly ~= 2.1.1
5280
pytest4.6: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
5381
pytest4.x: pytest ~= 4.0
82+
pytest4.x: pytest-cov ~= 2.5.1
83+
pytest4.x: pytest-randomly ~= 2.1.1
5484
pytest4.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
5585
pytest5.0: pytest ~= 5.0.0
86+
pytest5.0: pytest-cov ~= 2.5.1
87+
pytest5.0: pytest-randomly ~= 2.1.1
5688
pytest5.0: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
5789
pytest5.x: pytest ~= 5.0
90+
pytest5.x: pytest-cov ~= 2.5.1
91+
pytest5.x: pytest-randomly ~= 2.1.1
5892
pytest5.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
5993
pytest6.0: pytest ~= 6.0.0
60-
pytest6.0: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
94+
pytest6.0: pytest-cov ~= 2.10
95+
pytest6.0: pytest-randomly ~= 3.4
96+
pytest6.0: pytest-xdist ~= 2.0
6197
pytest6.x: pytest ~= 6.0
62-
pytest6.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
98+
pytest6.x: pytest-cov ~= 2.10
99+
pytest6.x: pytest-randomly ~= 3.4
100+
pytest6.x: pytest-xdist ~= 2.0
63101
mypy0.50: mypy >= 0.500, < 0.510
64102
mypy0.51: mypy >= 0.510, < 0.520
65103
mypy0.52: mypy >= 0.520, < 0.530
@@ -91,8 +129,6 @@ deps =
91129
mypy0.78: mypy >= 0.780, < 0.790
92130
mypy0.7x: mypy >= 0.700, < 0.800
93131

94-
pytest-cov ~= 2.5.1
95-
pytest-randomly ~= 2.1.1
96132
commands = py.test -p no:mypy --cov pytest_mypy --cov-fail-under 100 --cov-report term-missing {posargs:-n auto} tests
97133

98134
[testenv:publish]

0 commit comments

Comments
 (0)