From 0889b484378add9093ed5f5e5239b16df47c3b8c Mon Sep 17 00:00:00 2001 From: Nigel Jones Date: Fri, 6 Mar 2026 08:45:19 +0000 Subject: [PATCH 1/2] fix: explicit PYTHONPATH for isolated test subprocesses (#593) --- docs/examples/conftest.py | 8 ++++++++ test/conftest.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/docs/examples/conftest.py b/docs/examples/conftest.py index 212c310ff..cc80bc4dd 100644 --- a/docs/examples/conftest.py +++ b/docs/examples/conftest.py @@ -498,12 +498,20 @@ def __init__(self, **kwargs): super().__init__(**kwargs) def runtest(self): + import os + import pathlib + + repo_root = str(pathlib.Path(__file__).parent.parent.parent.resolve()) + env = os.environ.copy() + env["PYTHONPATH"] = f"{repo_root}{os.pathsep}{env.get('PYTHONPATH', '')}" + process = subprocess.Popen( [sys.executable, self.path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, # Enable line-buffering + env=env, ) # Capture stdout output and output it so it behaves like a regular test with -s. diff --git a/test/conftest.py b/test/conftest.py index e79446d67..6a924c405 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -251,6 +251,11 @@ def _run_heavy_modules_isolated(session, heavy_modules: list[str]) -> int: if markexpr: cmd.extend(["-m", markexpr]) + import pathlib + + repo_root = str(pathlib.Path(__file__).parent.parent.resolve()) + env["PYTHONPATH"] = f"{repo_root}{os.pathsep}{env.get('PYTHONPATH', '')}" + # Stream output in real-time while capturing for parsing process = subprocess.Popen( cmd, From 3748054f3ad0ab84e7b3d8675b27dcef716a315d Mon Sep 17 00:00:00 2001 From: Nigel Jones Date: Mon, 9 Mar 2026 12:17:58 +0000 Subject: [PATCH 2/2] fix: respect existing PYTHONPATH in subprocess tests Put existing PYTHONPATH first, then append repo_root as fallback. This is less invasive to user environments while still ensuring the local package is available when needed. --- docs/examples/conftest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/examples/conftest.py b/docs/examples/conftest.py index cc80bc4dd..3afd2fca7 100644 --- a/docs/examples/conftest.py +++ b/docs/examples/conftest.py @@ -503,7 +503,12 @@ def runtest(self): repo_root = str(pathlib.Path(__file__).parent.parent.parent.resolve()) env = os.environ.copy() - env["PYTHONPATH"] = f"{repo_root}{os.pathsep}{env.get('PYTHONPATH', '')}" + existing_pythonpath = env.get("PYTHONPATH", "") + env["PYTHONPATH"] = ( + f"{existing_pythonpath}{os.pathsep}{repo_root}" + if existing_pythonpath + else repo_root + ) process = subprocess.Popen( [sys.executable, self.path],