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

Avoid modifying path placeholders created by editable installs #1030

Merged
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
1 change: 1 addition & 0 deletions changelog/1028.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compatiblity issue between `looponfail` and editable installs.
3 changes: 2 additions & 1 deletion src/xdist/looponfail.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def init_worker_session(channel, args, option_dict):
newpaths = []
for p in sys.path:
if p:
if not os.path.isabs(p):
# Ignore path placeholders created for editable installs
if not os.path.isabs(p) and not p.endswith(".__path_hook__"):
p = os.path.abspath(p)
newpaths.append(p)
sys.path[:] = newpaths
Expand Down
39 changes: 39 additions & 0 deletions testing/test_looponfail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pathlib
import tempfile
import unittest.mock
from typing import List

Expand Down Expand Up @@ -191,6 +193,43 @@ def test_func():
control.loop_once()
assert control.failures

def test_ignore_sys_path_hook_entry(
self, pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
) -> None:
# Modifying sys.path as seen by the worker process is a bit tricky,
# because any changes made in the current process do not carry over.
# However, we can leverage the `sitecustomize` behavior to run arbitrary
# code when the subprocess interpreter is starting up. We just need to
# install our module in the search path, which we can accomplish by
# adding a temporary directory to PYTHONPATH.
tmpdir = tempfile.TemporaryDirectory()
with open(pathlib.Path(tmpdir.name) / "sitecustomize.py", "w") as custom:
print(
textwrap.dedent(
"""
import sys
sys.path.append('dummy.__path_hook__')
"""
),
file=custom,
)

monkeypatch.setenv("PYTHONPATH", tmpdir.name, prepend=":")

item = pytester.getitem(
textwrap.dedent(
"""
def test_func():
import sys
assert "dummy.__path_hook__" in sys.path
"""
)
)
control = RemoteControl(item.config)
control.setup()
topdir, failures = control.runsession()[:2]
assert not failures


class TestLooponFailing:
def test_looponfail_from_fail_to_ok(self, pytester: pytest.Pytester) -> None:
Expand Down