From 7830aec1f7d4c7763a74e01e422770d7d8c514df Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 13 May 2024 23:39:03 -0700 Subject: [PATCH] Use --pyargs to select package to test Also do not switch out of source path when running tests. - Allow testing src/ layout tests - Better support editable install tests See #185 --- spin/cmds/meson.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spin/cmds/meson.py b/spin/cmds/meson.py index 27671e1..58333a6 100644 --- a/spin/cmds/meson.py +++ b/spin/cmds/meson.py @@ -439,13 +439,14 @@ def test( ctx.invoke(build_cmd) package = cfg.get("tool.spin.package", None) + if package is None: + print( + "Please specify `package = packagename` under `tool.spin` section of `pyproject.toml`" + ) + raise SystemExit(1) + if (not pytest_args) and (not tests): - pytest_args = (package,) - if pytest_args == (None,): - print( - "Please specify `package = packagename` under `tool.spin` section of `pyproject.toml`" - ) - sys.exit(1) + tests = package site_path = _set_pythonpath() if site_path: @@ -494,12 +495,9 @@ def test( else: cmd = ["pytest"] - cwd = os.getcwd() pytest_p = _run( - cmd + ([f"--rootdir={site_path}"] if site_path else []) + list(pytest_args), - cwd=site_path, + cmd + list(pytest_args), ) - os.chdir(cwd) if gcov: # Verify the tools are present