diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-01-18 10:48:38 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-01-18 10:48:38 -0500 |
| commit | f767b4f59b14aa94d7c085173cb9360ba2d187eb (patch) | |
| tree | dd4c56464ba5676acbf385fd2de447cff913fc03 /setuptools | |
| parent | 31b0896bba77f21984dfad5a0b82fcd57bda9658 (diff) | |
| download | python-setuptools-git-f767b4f59b14aa94d7c085173cb9360ba2d187eb.tar.gz | |
Extract workaround for pytest-dev/pytest-xdist#376 as a fixture. Invoke the repair at the session level and only when xdist is present.
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/tests/fixtures.py | 19 | ||||
| -rw-r--r-- | setuptools/tests/test_build_meta.py | 11 |
2 files changed, 19 insertions, 11 deletions
diff --git a/setuptools/tests/fixtures.py b/setuptools/tests/fixtures.py index d975c0fc..d74b5f03 100644 --- a/setuptools/tests/fixtures.py +++ b/setuptools/tests/fixtures.py @@ -1,3 +1,5 @@ +import contextlib +import sys import shutil import pytest @@ -39,3 +41,20 @@ def tmp_src(request, tmp_path): tmp_src_path = tmp_path / 'src' shutil.copytree(request.config.rootdir, tmp_src_path) return tmp_src_path + + +@pytest.fixture(autouse=True, scope="session") +def workaround_xdist_376(request): + """ + Workaround pytest-dev/pytest-xdist#376 + + ``pytest-xdist`` tends to inject '' into ``sys.path``, + which may break certain isolation expectations. + Remove the entry so the import + machinery behaves the same irrespective of xdist. + """ + if not request.config.pluginmanager.has_plugin('xdist'): + return + + with contextlib.suppress(ValueError): + sys.path.remove('') diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index 3f1ba046..5dee8577 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -1,10 +1,8 @@ import os import shutil -import sys import tarfile import importlib from concurrent import futures -from contextlib import suppress import pytest @@ -46,15 +44,6 @@ class BuildBackendCaller(BuildBackendBase): def __call__(self, name, *args, **kw): """Handles aribrary function invocations on the build backend.""" - with suppress(ValueError): - # NOTE: pytest-xdist tends to inject '' into `sys.path` which - # NOTE: may break certain isolation expectations. To address - # NOTE: this, we remove this entry from there so the import - # NOTE: machinery behaves the same as in the default - # NOTE: sequential mode. - # Ref: https://github.com/pytest-dev/pytest-xdist/issues/376 - sys.path.remove('') - os.chdir(self.cwd) os.environ.update(self.env) mod = importlib.import_module(self.backend_name) |
