Skip to content

Add pytest-xdist 2.0.0 compatibility #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ def pytest_addoption(parser):
help="suppresses error messages about imports that cannot be resolved")


XDIST_WORKERINPUT_ATTRIBUTE_NAMES = (
'workerinput',
# xdist < 2.0.0:
'slaveinput',
)


def _get_xdist_workerinput(config_node):
workerinput = None
for attr_name in XDIST_WORKERINPUT_ATTRIBUTE_NAMES:
workerinput = getattr(config_node, attr_name, None)
if workerinput is not None:
break
return workerinput


def _is_master(config):
"""
True if the code running the given pytest.config object is running in
an xdist master node or not running xdist at all.
"""
return not hasattr(config, 'slaveinput')
return _get_xdist_workerinput(config) is None


def pytest_configure(config):
Expand All @@ -58,12 +74,12 @@ def pytest_configure(config):
config._mypy_results_path = tmp_f.name

# If xdist is enabled, then the results path should be exposed to
# the slaves so that they know where to read parsed results from.
# the workers so that they know where to read parsed results from.
if config.pluginmanager.getplugin('xdist'):
class _MypyXdistPlugin:
def pytest_configure_node(self, node): # xdist hook
"""Pass config._mypy_results_path to workers."""
node.slaveinput['_mypy_results_path'] = \
_get_xdist_workerinput(node)['_mypy_results_path'] = \
node.config._mypy_results_path
config.pluginmanager.register(_MypyXdistPlugin())

Expand Down Expand Up @@ -198,7 +214,7 @@ def _mypy_results(session):
results_path=(
session.config._mypy_results_path
if _is_master(session.config) else
session.config.slaveinput['_mypy_results_path']
_get_xdist_workerinput(session.config)['_mypy_results_path']
),
results_factory=functools.partial(
_mypy_results_factory,
Expand Down
44 changes: 40 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,84 @@ python =
[testenv]
deps =
pytest3.5: pytest ~= 3.5.0
pytest3.5: pytest-cov ~= 2.5.1
pytest3.5: pytest-randomly ~= 2.1.1
pytest3.5: pytest-xdist < 1.19.0
pytest3.6: pytest ~= 3.6.0
pytest3.6: pytest-cov ~= 2.5.1
pytest3.6: pytest-randomly ~= 2.1.1
pytest3.6: pytest-xdist < 1.28.0
pytest3.7: pytest ~= 3.7.0
pytest3.7: pytest-cov ~= 2.5.1
pytest3.7: pytest-randomly ~= 2.1.1
pytest3.7: pytest-xdist < 1.28.0
pytest3.8: pytest ~= 3.8.0
pytest3.8: pytest-cov ~= 2.5.1
pytest3.8: pytest-randomly ~= 2.1.1
pytest3.8: pytest-xdist < 1.28.0
pytest3.9: pytest ~= 3.9.0
pytest3.9: pytest-cov ~= 2.5.1
pytest3.9: pytest-randomly ~= 2.1.1
pytest3.9: pytest-xdist < 1.28.0
pytest3.10: pytest ~= 3.10.0
pytest3.10: pytest-cov ~= 2.5.1
pytest3.10: pytest-randomly ~= 2.1.1
pytest3.10: pytest-xdist < 1.28.0
pytest3.x: pytest ~= 3.5
pytest3.x: pytest-cov ~= 2.5.1
pytest3.x: pytest-randomly ~= 2.1.1
pytest3.x: pytest-xdist < 1.28.0
pytest4.0: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
pytest4.0: pytest ~= 4.0.0
pytest4.0: pytest-cov ~= 2.5.1
pytest4.0: pytest-randomly ~= 2.1.1
pytest4.0: pytest-xdist < 1.28.0
pytest4.1: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
pytest4.1: pytest ~= 4.1.0
pytest4.1: pytest-cov ~= 2.5.1
pytest4.1: pytest-randomly ~= 2.1.1
pytest4.1: pytest-xdist < 1.28.0
pytest4.2: attrs < 19.2.0 # https://github.com/pytest-dev/pytest/issues/5900
pytest4.2: pytest-cov ~= 2.5.1
pytest4.2: pytest-randomly ~= 2.1.1
pytest4.2: pytest ~= 4.2.0
pytest4.2: pytest-xdist < 1.28.0
pytest4.3: pytest ~= 4.3.0
pytest4.3: pytest-cov ~= 2.5.1
pytest4.3: pytest-randomly ~= 2.1.1
pytest4.3: pytest-xdist < 1.28.0
pytest4.4: pytest ~= 4.4.0
pytest4.4: pytest-cov ~= 2.5.1
pytest4.4: pytest-randomly ~= 2.1.1
pytest4.4: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest4.5: pytest ~= 4.5.0
pytest4.5: pytest-cov ~= 2.5.1
pytest4.5: pytest-randomly ~= 2.1.1
pytest4.5: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest4.6: pytest ~= 4.6.0
pytest4.6: pytest-cov ~= 2.5.1
pytest4.6: pytest-randomly ~= 2.1.1
pytest4.6: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest4.x: pytest ~= 4.0
pytest4.x: pytest-cov ~= 2.5.1
pytest4.x: pytest-randomly ~= 2.1.1
pytest4.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest5.0: pytest ~= 5.0.0
pytest5.0: pytest-cov ~= 2.5.1
pytest5.0: pytest-randomly ~= 2.1.1
pytest5.0: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest5.x: pytest ~= 5.0
pytest5.x: pytest-cov ~= 2.5.1
pytest5.x: pytest-randomly ~= 2.1.1
pytest5.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest6.0: pytest ~= 6.0.0
pytest6.0: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest6.0: pytest-cov ~= 2.10
pytest6.0: pytest-randomly ~= 3.4
pytest6.0: pytest-xdist ~= 2.0
pytest6.x: pytest ~= 6.0
pytest6.x: pytest-xdist ~= 1.0, < 1.30.0 # https://github.com/pytest-dev/pytest-xdist/issues/472
pytest6.x: pytest-cov ~= 2.10
pytest6.x: pytest-randomly ~= 3.4
pytest6.x: pytest-xdist ~= 2.0
mypy0.50: mypy >= 0.500, < 0.510
mypy0.51: mypy >= 0.510, < 0.520
mypy0.52: mypy >= 0.520, < 0.530
Expand Down Expand Up @@ -91,8 +129,6 @@ deps =
mypy0.78: mypy >= 0.780, < 0.790
mypy0.7x: mypy >= 0.700, < 0.800

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

[testenv:publish]
Expand Down