From 1b9b84e0667c6867ae597dd9e1912091d55db247 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 7 Feb 2024 14:50:15 -0800 Subject: [PATCH] pytest: use PYTHONPATH, not ., as first entry in sys.path Python 3.11 has the `-P` flag. For other Pythons, we invoke `pytest` directly, which seems to handle PYTHONPATH correctly. Closes #165 --- spin/cmds/meson.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spin/cmds/meson.py b/spin/cmds/meson.py index 84f2cf2..c2bc4e7 100644 --- a/spin/cmds/meson.py +++ b/spin/cmds/meson.py @@ -363,9 +363,13 @@ def test(ctx, pytest_args, n_jobs, tests, verbose, coverage=False, gcov=False): ] print(f'$ export PYTHONPATH="{site_path}"') + + if sys.version_info[:2] >= (3, 11): + cmd = [sys.executable, "-P", "-m", "pytest"] + else: + cmd = ["pytest"] _run( - [sys.executable, "-m", "pytest", f"--rootdir={site_path}"] + list(pytest_args), - cwd=site_path, + cmd + list(pytest_args), replace=True, )