-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
pytestCheckHook: Switch from python -m pytest
to simply pytest
?
#255262
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/python-package-testing-circular-import-in-a-version-py/33019/5 |
It is not a circular import, but this is a problem often encountered in extension modules generated by cython and others. some examples
|
Just for reference: pytestCheckHook is defined in And I think that -m behavior is to allow using a interpreter specific for testing. I don't know the usecases of this approach exactly as I am not the author of the hook. Do you think that an option to disable this behaviour and use pytest directly would be better? Like instead of that |
Instead of manually specifying the disabled tests and test paths in `checkPhase`, use the pytestCheckHook for that, and avoid the issue described at NixOS#255262 by removing the source directory.
Definitely that would be nice, but I'm not sure that's the only thing that is required here. At astropy/astropy#15316 (comment) I summarized some my findings regarding
Thanks for the examples! Indeed for the packages I tried to update and enable tests ( On the other hand over at #255260 a different solution was implemented eventually. |
Use NIX_CFLAGS_COMPILE = "-O2", due to upstream issue. cd "$out" to avoid circular import issue (discuessed downstream at at NixOS#255262).
Add some informatory comments, add doronbehar as maintainers, use `rec` instead of `let ... in`, add `pythonImportsCheck` and `pytestCheckHook`, use `cd $out` to handle issue NixOS#255262
Signed-off-by: lucasew <[email protected]>
Related to: NixOS#255262 and a follow-up to NixOS#251923 : - The NOSE_EXCLUDE environment variable was removed due to being unneeded, as upstream uses pytest for a long time now, and that disabled test was removed since. - Support parallel testing with pytest-xdist
Related to: NixOS#255262 . This allows Using the hook's builtin support for of `disabledTests` and `disabledTestPaths`.
The link to the build docs is outdated, and it doesn't have an updated direct alternative. While I tried to enable at least some of the tests, I encountered NixOS#255262 which is now linked in a comment.
Cython is a Python compiler that emits native .so modules. By default, python derivations run tests in the wrong directory to see these modules and tests fail. Issue #255262 documents the root cause and solution for this problem. This PR adds a description of the problem and the most common solution to the test troubleshooting list.
Summary of issue
Many packages in Nixpkgs that use cython extension modules, demonstrate some issues with running tests via
pytestCheckHook
, credit to @natsukium for helping figuring that out.Generally, the problem is that the extension modules are installed at the
installCheckPhase
at$out
, and are not$PWD
. This for instance may cause differences between runningpytest
and runningpython -m pytest
- hence the issue title. What's rather peculiar, is the fact that all packages that manage to overcome that use different schemes. The most common of them all is:Below is a list of such packages, and PRs that improved the situation a bit:
python3.pkgs.orange3
No PR was made yet to workaround the issue.python3.pkgs.matplotlib
, the common workaround doesn't work due to the directory structure of it, and no other workaround has been found yet (runningpytest
instead ofpython -m pytest
has also been tried). See also python310Packages.matplotlib: multiple cleanup commits #279317 .python3.pkgs.freud
(added at python311Packages.freud: init at 3.0.0 #313079) has tests that don't pass due to a circularImportError
, but do pass if you usepytest
and notpython -m pytest
.cd $out
didn't help forpytestCheckHook
.Below is the original issue description, opened before further details were investigated. Hence the issues there may be a bit outdated.
Original issue description
Describe the bug
While trying to enable tests for pyerfa, I noticed that I got circular imports errors as explained upstream here. I then ran
git grep circular import
and learned that another Python package,pyrevolve
is experiencing the same issue on NixOS:nixpkgs/pkgs/development/python-modules/pyrevolve/default.nix
Lines 36 to 46 in 46688f8
Steps To Reproduce
For each package that comes out in a
git grep circular import
search, I'll list what I learned, from most interesting, to less interesting:python3.pkgs.pyrevolve
Try to build it with this patch:
Which does the same as replacing
pytest
withpytestCheckHook
, and removing the overridingcheckPhase
. Note how the tests now fail.python3.pkgs.orange3
Seems like a very similar case to what happens in
python3.pkgs.pyrevolve
, but replacingpython -m pytest
withpytest
doesn't resolve the issue. I also haven't opened an issue upstream because I'm not sure whether this is our fault or theirs.I tested this issue using this patch
python3.pkgs.primer3
The circular import issue is mentioned there in a comment, but that comment seems maybe inaccurate to me, and the same testing failure is observed when adding
pytest
tonativeCheckInputs
, and when running manuallypytest
incheckPhase
. Comment improvement is in #255260python3.pkgs.xdot
Don't know why was the purpose of the
circular import
comment, maybe it was outdated. Now a fix for tests and update is available in #255254 .python3.pkgs.iniconfig
Not exactly this issue, but rather it is a form of #63168 . Improvement for the comment near it's
doCheck = false;
is in #255256 .Expected behavior
No difference between
pytest
andpython -m pytest
.Additional context
Problem was investigated also in https://discourse.nixos.org/t/python-package-testing-circular-import-in-a-version-py/33019/ .
Notify maintainers
@FRidh . Maybe
python3.pkgs.orange3
, andpython3.pkgs.pyrevolve
maintainers @lucasew and @AtilaSaraiva will be also interested.The text was updated successfully, but these errors were encountered: