-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
pytest in sage is broken, please make it really optional #33531
Comments
comment:1
This is what I have in mind (warning, this patch ignores whitespace to make it human-readable so it won't apply): DC = DocTestController(args, args.filenames)
err = DC.run()
+ if "pytest" in DC.options.optional:
try:
exit_code_pytest = 0
import pytest
@@ -163,5 +164,5 @@ if __name__ == "__main__":
if err == 0:
sys.exit(exit_code_pytest)
- else:
+
sys.exit(err) A proper patch (with whitespace changes) is: --- a/src/bin/sage-runtests
+++ b/src/bin/sage-runtests
@@ -147,21 +147,22 @@ if __name__ == "__main__":
DC = DocTestController(args, args.filenames)
err = DC.run()
- try:
- exit_code_pytest = 0
- import pytest
- pytest_options = ["--import-mode", "importlib"]
- if args.verbose:
- pytest_options.append("-v")
- exit_code_pytest = pytest.main(pytest_options + args.filenames)
- if exit_code_pytest == 5:
- # Exit code 5 means there were no test files, pass in this case
+ if "pytest" in DC.options.optional:
+ try:
exit_code_pytest = 0
-
- except ModuleNotFoundError:
- print("Pytest is not installed, skip checking tests that rely on it.")
-
- if err == 0:
- sys.exit(exit_code_pytest)
- else:
- sys.exit(err)
+ import pytest
+ pytest_options = ["--import-mode", "importlib"]
+ if args.verbose:
+ pytest_options.append("-v")
+ exit_code_pytest = pytest.main(pytest_options + args.filenames)
+ if exit_code_pytest == 5:
+ # Exit code 5 means there were no test files, pass in this case
+ exit_code_pytest = 0
+
+ except ModuleNotFoundError:
+ print("Pytest is not installed, skip checking tests that rely on it.")
+
+ if err == 0:
+ sys.exit(exit_code_pytest)
+
+ sys.exit(err) |
Branch: u/tornaria/pytest-optional |
Commit: |
comment:2
And here's the commit, ready for review. Once pytest is working reliably, New commits:
|
Author: Gonzalo Tornaría |
comment:3
This looks like a good fix |
comment:4
Currently pytest is an optional package, so you have to install it manually and only in that case the tests are run. Why do you think an additional switch is necessary?
The long term goal is to use pytest also for run the doctests (completely removing sage's custom doctest runner). So I don't like to introduce switches that differentiate between doctests and "pytests". The error that occurs while testing the all module should be fixed with #30748 (ready for review for months). |
comment:5
#30748 does not describe itself as fixing a bug. |
Dependencies: #32975 |
comment:7
Replying to @tobiasdiez:
Maybe pytest is installed because it's needed for another purpose. In my case, sage uses system python packages and pytest was installed in the system for whatever reason. I don't even remember, but it's kind of surprising (and annoying) that doctesting breaks because of that. My proposal is to make the choice to run pytest explicit rather than implicit because one just happens to have pytest installed, at least while you are developing it.
If/when that happens, this will be easy to re evaluate.
That's just one random example. Doctesting any files is broken, since the logic in sage-runtests will always call pytest with all given arguments rather than only the files that need to be run by pytest. Replying to @mkoeppe:
It looks to me independent. That ticket doesn't seem to touch the logic in sage-runtests. |
comment:8
I can see that it's annoying that some things are not working perfectly. On the other hand, I think its also important to get experience with pytest and find these little issues that popup in different settings. Thus, I'm not a big fan of hiding pytest behind two switches.
Yes, pytest is always run on these files (if you use
The first issue should be fixed anyway because one would encounter the same issues when using sage as a library (which is pushed by the modularization effort). And the second issue should be fixed with #31924. Currently, pytest is invoked as part of some github actions runs and this should also be kept to not lower the test coverage. So one would need to pass the |
comment:9
I'll add an amusing failure I have now linked to pytest in sage-on-gentoo to the list of issues to fix. I hope #31924 will cover it. I have noticed the following doctest failure on and off
This only happens if pytest is available and found. To put things into perspective this is the code section tested with all you need to know to reproduce the behavior
Why is it happening? Well I manually ran the above line with the temporary script
The doctest test doctesting and it ends up with a classic #31924 kind of failure. |
comment:10
Replying to @tobiasdiez:
But these are not "little issues", they actually break It's absolutely crucial that one can pass individual files to
All I'm asking is for ONE switch to run pytest. I suggested that it defaults to OFF while all the "little issues" are ironed out, and that it could default to ON later.
Also: If the current standing is that
That sounds a good idea, those github actions need to be aware of pytest anyway (as in: install optional package pytest, etc) so you may as well turn the "pytest switch" on while it defaults to off. This gives you the opportunity and freedom to develop pytest integration without fear of breaking standard doctesting. I'd say it's better not move tests from the sage doctest framework to pytest framework until everything is working, pytest is a standard packages, and the "pytest switch" defaults to on. |
comment:11
I have a fix in #31924, please review |
comment:12
I believe #31924 makes this unnecessary. |
comment:13
Is there still brokenness, or can we close this ticket? |
comment:14
I'm running with undef After #33521, this means pytest is never run, so the issue is gone 👍️. OTOH, if I actually set
This may be because pytest is too old in void linux (6.2.5, instead of 7.x). If I comment out the definition of However, I couldn't help but notice that pytest will use a single thread to run, which is a HUGE regression if tests start migrating from the sage doctest framework to pytest !!! Right now running pytest through all these 9 files takes 80s, while the doctest step in --long --all mode takes just 312s wall time (using 36 threads). Out of all the files
This goes away if I change the import to be absolute ( |
Changed author from Gonzalo Tornaría to none |
Reviewer: Gonzalo Tornaría |
comment:16
I take 👍️ as positive review |
Changed branch from u/tornaria/pytest-optional to none |
Changed commit from |
comment:18
Replying to @tornaria:
Yes, that's what positive review with the milestone "sage-duplicate/invalid/wontfix" indicates. It's not really necessary to remove the branch; it won't be accidentally merged. |
src/bin/sage-runtests
to run pytest (see 719e442)Expected behaviour (this is what happens when pytest is patched out in
sage-runtests
):My proposal:
In fact pytest should only run when there's some file
*_test.py
in the list of files, and only in those files. I think DC already traversed the filesystem in search of files, so instead of having pytest traverse the filesystem again, just filter the list of files that DC obtained for*_test.py
and run pytest just on those and only if there's some.Even if/after pytest integration is fixed, there are advantages to place it behind a feature flag so there's an easy way to run doctests skipping pytest (just add
--optional=sage
or whatever else one wants to test, leaving outpytest
)Depends on #31924
CC: @tobiasdiez @mkoeppe
Component: doctest framework
Reviewer: Gonzalo Tornaría
Issue created by migration from https://trac.sagemath.org/ticket/33531
The text was updated successfully, but these errors were encountered: