Commit f767b4f5 authored by Jason R. Coombs's avatar Jason R. Coombs

Extract workaround for pytest-dev/pytest-xdist#376 as a fixture. Invoke the...

Extract workaround for pytest-dev/pytest-xdist#376 as a fixture. Invoke the repair at the session level and only when xdist is present.
parent 31b0896b
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('')
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment