diff --git a/docs/examples/conftest.py b/docs/examples/conftest.py index 212c310ff..3afd2fca7 100644 --- a/docs/examples/conftest.py +++ b/docs/examples/conftest.py @@ -498,12 +498,25 @@ 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() + 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], 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,