jaraco / pytest-enabler

MIT License
3 stars 5 forks source link

INTERNALERROR in Setuptools with xdist and cov installed #1

Closed jaraco closed 3 years ago

jaraco commented 3 years ago

In pypa/setuptools#2459, webknjaz is working on a patch that enables xdist. On that PR, I add the following change to rely on pytest-enabler to pass -n auto when pytest-xdist is enabled:

diff --git a/pyproject.toml b/pyproject.toml
index 0bc2a46f4..4e80bdc1a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,6 +24,9 @@ addopts = "--flake8"
 [pytest.enabler.cov]
 addopts = "--cov"

+[pytest.enabler.xdist]
+addopts = "-n auto"
+
 [tool.towncrier]
     package = "setuptools"
     package_dir = "setuptools"
diff --git a/pytest.ini b/pytest.ini
index df30b8227..03fc773cf 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -4,9 +4,6 @@ addopts=
    --doctest-modules
    --doctest-glob=pkg_resources/api_tests.txt
    -r sxX
-
-   # `pytest-xdist`:
-   -n auto
 doctest_optionflags=ALLOW_UNICODE ELLIPSIS
 # workaround for warning pytest-dev/pytest#6178
 junit_family=xunit2

But when I do, the tests fail with an INTERNALERROR in the pytest-cov codebase.

python develop-inst-noop: /Users/jaraco/code/public/pypa/setuptools
python installed: apipkg==1.5,appdirs==1.4.4,attrs==20.3.0,black==20.8b1,click==7.1.2,contextlib2==0.6.0.post1,coverage==5.3.1,distlib==0.3.1,docutils==0.16,execnet==1.7.1,filelock==3.0.12,flake8==3.8.4,flake8-2020==1.6.0,iniconfig==1.1.1,jaraco.apt==2.0,jaraco.context==3.0.0,jaraco.envs==2.1.0,jaraco.functools==3.1.0,mccabe==0.6.1,mock==4.0.3,more-itertools==8.6.0,mypy==0.790,mypy-extensions==0.4.3,packaging==20.8,path==15.0.1,path.py==12.5.0,pathspec==0.8.1,Paver==1.3.4,pip==20.3.3,pluggy==0.13.1,py==1.10.0,pycodestyle==2.6.0,pyflakes==2.2.0,pyparsing==2.4.7,pytest==6.2.1,pytest-black==0.3.12,pytest-checkdocs==2.2.0,pytest-cov==2.10.1,pytest-enabler==1.0.0,pytest-fixture-config==1.7.0,pytest-flake8==1.0.7,pytest-forked==1.3.0,pytest-mypy==0.8.0,pytest-shutil==1.7.0,pytest-virtualenv==1.7.0,pytest-xdist==2.2.0,pytz==2020.5,regex==2020.11.13,-e git+gh://pypa/setuptools@5f3d12316dc4e3c3f638786668cee38ff5a73bd3#egg=setuptools,six==1.15.0,tempora==4.0.1,termcolor==1.1.0,toml==0.10.2,tox==3.21.1,typed-ast==1.4.2,typing-extensions==3.7.4.3,virtualenv==20.3.1,wheel==0.36.2,yg.lockfile==2.3,zc.lockfile==2.0
python run-test-pre: PYTHONHASHSEED='1203580294'
python run-test: commands[0] | pytest
============================= test session starts ==============================
platform darwin -- Python 3.9.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
cachedir: .tox/python/.pytest_cache
rootdir: /Users/jaraco/code/public/pypa/setuptools, configfile: pytest.ini
plugins: flake8-1.0.7, mypy-0.8.0, checkdocs-2.2.0, black-0.3.12, shutil-1.7.0, enabler-1.0.0, virtualenv-1.7.0, cov-2.10.1, xdist-2.2.0, forked-1.3.0
gw0 I / gw1 I / gw2 I / gw3 I / gw4 I / gw5 I / gw6 I / gw7 I
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/_pytest/main.py", line 267, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/xdist/dsession.py", line 78, in pytest_sessionstart
INTERNALERROR>     nodes = self.nodemanager.setup_nodes(putevent=self.queue.put)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/xdist/workermanage.py", line 65, in setup_nodes
INTERNALERROR>     return [self.setup_node(spec, putevent) for spec in self.specs]
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/xdist/workermanage.py", line 65, in <listcomp>
INTERNALERROR>     return [self.setup_node(spec, putevent) for spec in self.specs]
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/xdist/workermanage.py", line 73, in setup_node
INTERNALERROR>     node.setup()
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/xdist/workermanage.py", line 260, in setup
INTERNALERROR>     self.config.hook.pytest_configure_node(node=self)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/jaraco/code/public/pypa/setuptools/.tox/python/lib/python3.9/site-packages/pytest_cov/plugin.py", line 239, in pytest_configure_node
INTERNALERROR>     self.cov_controller.configure_node(node)
INTERNALERROR> AttributeError: 'Central' object has no attribute 'configure_node'
ERROR: InvocationError for command /Users/jaraco/code/public/pypa/setuptools/.tox/python/bin/pytest (exited with code 3)
___________________________________ summary ____________________________________
ERROR:   python: commands failed

Running the tests with pytest-cov disabled (tox -- -p no:cov) allows the tests to run with xdist enabled.

jaraco commented 3 years ago

The issue appears to be that pytest-cov varies depending on enablement of xdist, so when the enabler is bootstrapping coverage, it needs to make the command-line parameters for all enabled plugins are already parsed (not just those for cov).