-
-
Notifications
You must be signed in to change notification settings - Fork 649
Run function field TestSuites via pytest #40443
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
Conversation
0739c79
to
4d8f75a
Compare
These slow tests arose by mistake (inserting a |
4d8f75a
to
df01acb
Compare
I think it's a good idea to move those tests to pytest. As a small suggestion, what do you think about using parametrized tests since they all just call the test suite? Would make easier in the future to actually move the test suite methods to pytest (see #30738) |
Sure, what do you think should be parameterized? I would guess the field and number of TestSuite runs, but then we run into a problem because the "setup" code to generate the fields is itself a tiny bit slow and we don't want to run it while pytest is collecting tests. There are docs on working around that, but the constructions of the fields/rings are intertwined here, unlike in that example. We don't want to repeatedly construct them, so it's not obvious to me how to cleanly parameterize everything without e.g. ugly manual cacheing. I rarely use pytest however so I may be missing something obvious. |
How exactly does pytest helps here? |
Okay, then let's leave it like its currently. Would be nice to see if the tests are actually passing on CI. I tried to reactivate pytest in #40446, but there are a few strange errors (that I don't have the time right now to investigate further) |
Pytest isn't needed to speed up the tests, but there are some additional reasons to prefer it for these unit-test suites. The main benefit of doctests is that they double as readable examples, but in this case the example is just In the cons column,
|
I'm neutral to this. Having documentation far from actual code is a bad idea (people will modify the code and forget about the documentation), but for tests, it's not a problem (if people forget to modify tests, it will fails loudly) On the other hand, then you need to jump between two files. IDE has split window, but still not as convenient.
Is this a corollary of
?
This is backwards. Ultimately, the "correct" (supported) way to use Sage is to type the commands directly into the command-line, so to test new code, you first type the code directly into the command-line (or jupyter notebook), then copy the whole session into doctest. Then you only run the subset you want without the extra overhead of remembering what's the test name you want to run.
|
The main reason for the nonnegative line count is that I've left the existing examples in This is the warning that pytest displays if
Not entirely. The doctest runner is just big and complicated. When it starts, it does all of this crap:
Beyond that, doctests are inherently slow because they can only compare strings. Every test output is converted to a string, and then subjected to a string comparison. If you want to test a method that generates the first 1,000 primes, you can quickly do that with
is horrendously slow.
I don't believe you :P Sage has always been usable as a library. But what I am getting at is that certain tests need to be run many times. Take for example the In practice what I do is recreate the tests in a new python file and call |
If I understood correctly, you want to say the reason why writing code for a new package is annoying is because if you read Sage from the syntax sugar, you wouldn't know how to write it in non-syntax-sugar way. While this is valid, it is somewhat backward: if we could write with syntax sugar in both Sage shell and package file, problem would be solved. And the reason why the syntax sugar was invented is because it's more convenient to use the syntax sugar than without.
You can do
What else are you doing, |
But we can't have the sugar in both places. And I'm not sure that saving one line is worth having the mental model broken in e.g.
where variables are injected into the namespace and existing names are clobbered.
I completely admit that I could have fixed this inside the doctest.
If you're doing
? That's OK too. What if computing the primes displays a warning? It depends, but sometimes we just ignore it. All of these preprocessing steps are performed on a long string. Absolute/relative tolerance is implemented as a regex. The "optional" and "long time" tags themselves are strings that need to be parsed, rather than code. It's all waaay slower than it has to be.
A "for" loop only looks nice in this case because the I generally copy/paste the tests into a new file and use |
Anyway, about the pull request—if I understood correctly,
I'm positive to the former, but negative to the latter. |
I'm surprised that the migration to pytest is such a controversial topic. Since a year or so, pytest is a standard package - and it became standard with the idea to a) make it the default test runner and b) to migrate |
Could you please merge #40474 into this PR (perhaps only temporarily) to check that the pytest tests are indeed working across all system configs. |
The tests are still slow, even over
|
61ece0c
to
c4ee844
Compare
Done. I also spent some time figuring out how to parameterize these tests. There's a little extra boilerplate now but I'm happy with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nicer indeed! There are a few small linter issues. Feel free to set it to positive review after fixing those.
Move the existing TestSuite() runs for function fields to pytest. These are long/slow tests that are not instructive as examples in the documentation. As a side effect, we fix some "slow doctest" warnings present in the CI.
…alls The TestSuite() runs for this file have been moved to pytest; we no longer want to run them as part of the doctest suite.
I'm not sure if we should be installing pytest source files, but for now let's do so for consistency.
20a3909
to
b9e65d1
Compare
Thanks! I'm going to remove the dependency on #40474 but we should be able to get them merged simultaneously. |
in that case, pytest makes it worse. Now if some change makes the test takes 300s instead of 120s, nobody notices. While if a (in other words, this is equivalent to
) this problem remains as well:
|
I'm reluctant to argue these points since largely you are right and I risk coming across as petty. That's not my intention, I just like talking about this stuff. Pytest can output slow test information. No one is using it at the moment, but it's there, and doesn't require the same amount of custom code that the slow doctest warnings do. So at least in theory such a regression could be made just as noticeable and I think it's a big plus that we don't have to maintain it. But, the format of pytests makes a regression much less likely. The regression was originally introduced because an extra example was added at the end of the module's The pytest formulation in contrast lists the dependencies between tests explicitly. In my latest commit there are several fixtures and the fixtures they depend on are listed in the function signature, e.g. @pytest.fixture
def M(K, R, S):
x = K.gen()
y = R.gen()
L = K.extension(y**3 - (x**3 + 2*x*y + 1/x))
t = S.gen()
return L.extension(t**2 - x*y) This makes it clear that changing
The CI aside, the doctest runner has its own per-file timeout with defaults in elif options.long:
options.timeout = int(os.getenv('SAGE_TIMEOUT_LONG', 30 * 60))
else:
options.timeout = int(os.getenv('SAGE_TIMEOUT', 10 * 60)) These are not an issue with pytest; nor are the "slow doctest" warnings (which I know you have another solution for). At least for real users, using pytest here does lessen the likelihood of a failure due to doctest timeout. In any case, the argument for moving these to pytest is ultimately that the community has agreed on it:
In addition to the other benefits, pytest is the standard python testing tool. Everyone knows it, so allowing (potential) new contributors to use it instead of learning the 20 years of quirks and cruft in |
sagemathgh-40443: Run function field TestSuites via pytest * Fix two slow doctest warnings in the CI by moving these tests to pytest. * Speed some test suites up by using fewer repeated runs. Nowadays we run the tests on every PR, so repeated runs within repeated runs are less valuable. * Use `QQ` instead of `QQbar` for some tests where this was the original intention. * Clean up the docs by eliminating pure-test code from the docstrings. URL: sagemath#40443 Reported by: Michael Orlitzky Reviewer(s): Tobias Diez
QQ
instead ofQQbar
for some tests where this was the original intention.