diff --git a/src/xdist/plugin.py b/src/xdist/plugin.py index 1eba32b8..d5693861 100644 --- a/src/xdist/plugin.py +++ b/src/xdist/plugin.py @@ -1,9 +1,12 @@ import os import uuid +import sys import py import pytest +_sys_path = list(sys.path) # freeze a copy of sys.path at interpreter startup + def pytest_xdist_auto_num_workers(): try: diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 7f95b5cc..d79f0b38 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -219,12 +219,14 @@ def setup_config(config, basetemp): channel = channel # noqa workerinput, args, option_dict, change_sys_path = channel.receive() - if change_sys_path: + if change_sys_path is None: importpath = os.getcwd() sys.path.insert(0, importpath) os.environ["PYTHONPATH"] = ( importpath + os.pathsep + os.environ.get("PYTHONPATH", "") ) + else: + sys.path = change_sys_path os.environ["PYTEST_XDIST_TESTRUNUID"] = workerinput["testrunuid"] os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"] diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py index 8fed077e..2c4f1a68 100644 --- a/src/xdist/workermanage.py +++ b/src/xdist/workermanage.py @@ -9,6 +9,7 @@ import execnet import xdist.remote +from xdist.plugin import _sys_path def parse_spec_config(config): @@ -261,7 +262,8 @@ def setup(self): remote_module = self.config.hook.pytest_xdist_getremotemodule() self.channel = self.gateway.remote_exec(remote_module) # change sys.path only for remote workers - change_sys_path = not self.gateway.spec.popen + # restore sys.path from a frozen copy for local workers + change_sys_path = _sys_path if self.gateway.spec.popen else None self.channel.send((self.workerinput, args, option_dict, change_sys_path)) if self.putevent: