From 6d91c8339bf3ce5c0aa9a62e981752101803d50c Mon Sep 17 00:00:00 2001 From: Leonardo Rochael Almeida Date: Thu, 20 Aug 2020 18:58:10 -0300 Subject: [PATCH] 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. --- src/pytest_mypy.py | 24 ++++++++++++++++++++---- tox.ini | 44 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 80a5833..b58b3dc 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -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): @@ -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()) @@ -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, diff --git a/tox.ini b/tox.ini index 73ecf61..ff00899 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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]