Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not change PYTHONPATH or sys.path on workers #397

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/376.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 11 additions & 8 deletions xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only after archeology ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

The only archaeology I could find is this one: #376 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d81ffaa

based on this not having it breaks remote workers, and tox is completely unusable to feed those as tox never got that part done

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])
Expand Down
4 changes: 3 additions & 1 deletion xdist/workermanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down