Skip to content

Commit f8d51aa

Browse files
committed
Do not change PYTHONPATH or sys.path on local workers
Fix pytest-dev#376
1 parent ca94bda commit f8d51aa

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

changelog/376.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The current directory is no longer added ``sys.path`` for local workers, only for remote connections.
2+
3+
This behavior is surprising because it makes xdist runs and non-xdist runs to potentially behave differently.

xdist/remote.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,20 @@ def remote_initconfig(option_dict, args):
251251

252252

253253
if __name__ == "__channelexec__":
254+
import py
255+
254256
channel = channel # noqa
255-
workerinput, args, option_dict = channel.receive()
256-
importpath = os.getcwd()
257-
sys.path.insert(0, importpath) # XXX only for remote situations
258-
os.environ["PYTHONPATH"] = (
259-
importpath + os.pathsep + os.environ.get("PYTHONPATH", "")
260-
)
257+
workerinput, args, option_dict, change_sys_path = channel.receive()
258+
259+
if change_sys_path:
260+
importpath = os.getcwd()
261+
sys.path.insert(0, importpath)
262+
os.environ["PYTHONPATH"] = (
263+
importpath + os.pathsep + os.environ.get("PYTHONPATH", "")
264+
)
265+
261266
os.environ["PYTEST_XDIST_WORKER"] = workerinput["workerid"]
262267
os.environ["PYTEST_XDIST_WORKER_COUNT"] = str(workerinput["workercount"])
263-
# os.environ['PYTHONPATH'] = importpath
264-
import py
265268

266269
config = remote_initconfig(option_dict, args)
267270
config._parser.prog = os.path.basename(workerinput["mainargv"][0])

xdist/workermanage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ def setup(self):
245245
option_dict["basetemp"] = str(basetemp.join(name))
246246
self.config.hook.pytest_configure_node(node=self)
247247
self.channel = self.gateway.remote_exec(xdist.remote)
248-
self.channel.send((self.workerinput, args, option_dict))
248+
# change sys.path only for remote workers
249+
change_sys_path = not self.gateway.spec.popen
250+
self.channel.send((self.workerinput, args, option_dict, change_sys_path))
249251
if self.putevent:
250252
self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)
251253

0 commit comments

Comments
 (0)