-
Notifications
You must be signed in to change notification settings - Fork 20
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
--pyargs
not used if -k
is used
#204
Comments
🤔 if tests and "--pyargs" not in pytest_args:
pytest_args = ("--pyargs", tests) + pytest_args Yeah, there's the culprit. Although tests are supposed to be set. Will figure out what's going on and submit a fix. |
The fix is going to be slightly more restrictive in some cases, since
will need to be invoked as
There's no other way to really know when the pytest arguments are intended to specify tests. |
Those always need to use the `-k` flag. We cannot avoid setting `--pyargs`, otherwise src/ package layouts won't work. Closes scientific-python#204
I think when using
Probably if It should not usually be necessary to combine |
Note that this also works: $ spin test -t flint.test.test_all::test_fmpz_mod_poly
...
$ /home/oscar/.pyenv/versions/3.11.3/envs/python-flint-3.11/bin/python3.11 -P -m pytest --pyargs flint.test.test_all::test_fmpz_mod_poly
======================================== test session starts ========================================
platform linux -- Python 3.11.3, pytest-7.4.3, pluggy-1.2.0
rootdir: /home/oscar/current/active/python-flint
plugins: hypothesis-6.84.2, cov-4.1.0, split-0.8.1, timeout-2.1.0, doctestplus-1.0.0, xdist-3.3.1
collected 1 item
src/flint/test/test_all.py . [100%]
========================================= 1 passed in 1.02s ========================================= |
pytest handles that fine, although it may be abusing the syntax. What is the correct syntax for "look on the system path for the module, but interpret what I give you as a file path". I've marked #205 as draft, since the following doesn't work:
I'd need to expand the test suite as well to make sure we capture all the cases correctly. If you have time to help extricate and understand all the use-cases (file-vs-module test specification, test specification directly or via pytest args, src vs non-source layout, editable vs meson-build-path), I'd appreciate it. |
I think that there are really just two cases that matter:
For in-package tests you should always use the module's import name and it should always be discovered via For out-of-package tests the path to the test file needs to be given somehow and then it should maybe be treated as a standalone file. If the tests are themselves a package (separate from the library package) then if they are supposed to be installed by meson this is really just in-package tests. If they are in a package but not supposed to be installed then again they should be located by import module name but somehow spin/pytest should be configured to add the relevant base directory to sys.path. I can't really think of a case where it makes sense to use file paths rather than module names besides a single file test script that is run like |
This is one of the most interesting parts of this project; learning developers' different work styles! E.g., I exclusively use the file-path mode of invoking tests, because I can TAB-complete at the prompt to find the filename I want to run. |
Yeah, I know and I do that as well with sympy. The thing is that it doesn't work in a src layout and if you think about it then really every nontrivial project should use the src layout (even if it is pure Python and doesn't really have a "build step"). A lot of legacy codebases don't use src layout and it's not clear whether it is worth changing them. We should strive to make src-layout-plus-out-of-tree-build a first class citizen in new tooling and new projects though. Of course spin could have a completion interface like other CLI tools and that could discover things more intelligently than just by looking at the file system. Then you could complete the test function names as well as the module names and the interpretation of the arguments would always be well defined and unambiguous. This also works in a src layout btw: $ spin test -t src/flint/test/test_all.py::test_fmpz_mod_poly That one is useful because that is what pytest outputs at the end of the test report if e.g. the test fails: $ spin test
...
$ /home/oscar/.pyenv/versions/3.11.3/envs/python-flint-3.11/bin/python3.11 -P -m pytest --pyargs flint
...
src/flint/test/test_all.py:1850: ZeroDivisionError
====================================== short test summary info ======================================
FAILED src/flint/test/test_all.py::test_fmpz_mod_poly - ZeroDivisionError: division by zero
=================================== 1 failed, 48 passed in 1.39s ==================================== But how does pytest figure out how to import that file? It is doing some strange magic to make it work by guessing which directory is the base of the import structure. That guessing should not be necessary and results from trying to make things convenient but then making them also poorly defined at the same time. Really pytest should output the module name here rather than a file path (especially since we used |
Yes, strange magic 👻 We could potentially detect when |
Even more simply, we could detect when |
I think this is the more important question for If the tests are not shipped then that presumably means they are not in the build directory and therefore |
For now, I consider this expected behavior: if you specify additional args to pytest, we do not mess with those args. However, if you use |
Closed by #213 |
I'm seeing this problem with a src-layout in both an editable install and also a plain
spin test
. If I pass-k
through topytest
then--pyargs
is not also passed:A plain
spin test
works because it uses--pyargs
:The text was updated successfully, but these errors were encountered: