From f8d51aab57ebe0a8d579fadd3e30abb6091870c6 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 8 Jan 2019 09:16:38 -0200 Subject: [PATCH] Do not change PYTHONPATH or sys.path on local workers Fix #376 --- changelog/376.feature.rst | 3 +++ xdist/remote.py | 19 +++++++++++-------- xdist/workermanage.py | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 changelog/376.feature.rst diff --git a/changelog/376.feature.rst b/changelog/376.feature.rst new file mode 100644 index 00000000..7dbbb016 --- /dev/null +++ b/changelog/376.feature.rst @@ -0,0 +1,3 @@ +The current directory is no longer added ``sys.path`` for local workers, only for remote connections. + +This behavior is surprising because it makes xdist runs and non-xdist runs to potentially behave differently. diff --git a/xdist/remote.py b/xdist/remote.py index b0092e06..58744d0e 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -251,17 +251,20 @@ def remote_initconfig(option_dict, args): if __name__ == "__channelexec__": + import py + channel = channel # noqa - workerinput, args, option_dict = channel.receive() - importpath = os.getcwd() - sys.path.insert(0, importpath) # XXX only for remote situations - os.environ["PYTHONPATH"] = ( - importpath + os.pathsep + os.environ.get("PYTHONPATH", "") - ) + workerinput, args, option_dict, change_sys_path = channel.receive() + + if change_sys_path: + importpath = os.getcwd() + sys.path.insert(0, importpath) + os.environ["PYTHONPATH"] = ( + importpath + os.pathsep + os.environ.get("PYTHONPATH", "") + ) + os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"] os.environ["PYTEST_XDIST_WORKER_COUNT"] = str(workerinput["workercount"]) - # os.environ['PYTHONPATH'] = importpath - import py config = remote_initconfig(option_dict, args) config._parser.prog = os.path.basename(workerinput["mainargv"][0]) diff --git a/xdist/workermanage.py b/xdist/workermanage.py index 111b86f4..75465d0a 100644 --- a/xdist/workermanage.py +++ b/xdist/workermanage.py @@ -245,7 +245,9 @@ def setup(self): option_dict["basetemp"] = str(basetemp.join(name)) self.config.hook.pytest_configure_node(node=self) self.channel = self.gateway.remote_exec(xdist.remote) - self.channel.send((self.workerinput, args, option_dict)) + # change sys.path only for remote workers + change_sys_path = not self.gateway.spec.popen + self.channel.send((self.workerinput, args, option_dict, change_sys_path)) if self.putevent: self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)