-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
Replace custom Sage unit test discovery by pytest #30738
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
Are you aware that the crucial point of our _test methods, in particular those provided in the category framework, is that objects of subclasses run these tests? |
comment:3
Yes, and this structure is also somewhat reflected in the new code as the tests for the subclasses inherit from the general base test class. If I understood the code correctly, then the main purpose of these subclasses (with respect to the tests) is to provide the examples (e.g. using the |
comment:4
Replying to @tobiasdiez:
No, the category classes provide mixins for dynamically generated classes for all |
comment:5
Sure, but that doesn't seem to be important for the tests itself. Take for example the tests in One question though: is the purpose of these tests to check that one general implementation is correct for all these examples (e.g |
comment:6
Replying to @tobiasdiez:
The latter. |
comment:7
Thanks, I thought so too. Then the current file structure should be right. |
comment:8
I do not know enough about pytest. Can you expand the ticket description to explain how the test discovery works after the ticket, and how it ensures that still the same things get tested? |
This comment has been minimized.
This comment has been minimized.
comment:11
I've extended the ticket description. Does this clarify your questions? The test |
comment:12
Sorry, I still don't get it. The branch as it is on the ticket - do you claim that it still tests the same objects as before? |
comment:13
If you run
So the idea would be to replace this doctest by |
comment:14
Replying to @tobiasdiez:
A few? Currently |
comment:15
Sure, there are quite a lot of instances where a So the replacement dictionary roughly speaking looks like:
The idea is not to change the way the tests cases are provided (although that may certainly be improved in the future) but to replace sage's only implementation of test discovery and invocation by what is probably the most establish Python testing framework. |
comment:16
So in your design, there would be a hierarchy of |
comment:17
Yes! Every parent class would have a corresponding test class which specifies which general axioms this parent class wants to adhere to. This is done by deriving from one or more generic test classes (the one in the branch should probably be renamed to |
comment:18
Okay, but the parent classes are dynamic classes formed by mixing in axioms. |
comment:19
Replying to @tobiasdiez:
Thanks for this clarification. I'm setting this ticket to "needs_work" because the branch in this form is not complete -- it effectively removes existing tests for Overall I think there is a conflict here between the dynamic nature of our category system and what seems to amount to a static determination of what objects to test for what properties (in the proposed changes). |
comment:20
I'm not that familiar yet with the category framework. When you say "dynamic classes formed by mixing in axioms" you mean something like I agree, this branch has not yet feature parity with the master branch. Before I invest more time into it, I just wanted to confirm that this idea would be worth looking at in general. |
comment:21
Replying to @tobiasdiez:
Yes, things like this. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed keywords from none to testsuite |
comment:74
Why did you change the milestone? I don't see anything that would prevent this being merged soon (except for the missing review). |
comment:75
There's been no activity, and it's not clear if there are any developers who would be interested in rewriting the entirety of our test suite. |
comment:76
While being a relatively huge project, I think, a completely migration can be done in a relatively straightforward way with an overseeable time investment. I would definitely up for doing this alone if necessary. So I'm appreciate if this ticket could be reviewed soon. Thanks! |
comment:77
You have received review comments: comment:45, comment:48, etc. |
This comment has been minimized.
This comment has been minimized.
comment:80
Replying to @mkoeppe:
I've fixed comment:45. To comment:48 I've already reacted in comment:49. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch has merge conflicts |
Currently, Sage code contains
_test_xyz
methods that are invoked via doctests and discovered via a customTestSuite
class. This ticket is to replace this custom test discovery by the use of the established pytest framework https://docs.pytest.org/ (this is in line with #28936 - using mainstream Python test infrastructure).Advantages of this approach:
TestSuite
code).*_test.py
files can easily be excluded from distribution.Disadvantages of this approach:
*_test.py
and test methods must start withtest_
).In order to migrate, the following changes are necessary:
_test_xyz
from a categorymodule
to new file<module>_test.py
(e.g.finite_semigroups_test.py
).self_tester
).TestFiniteSemigroup
).category_instances()
in this test class returning a list of instances to test.For the moment, I did this only for a few test methods in
sets_cat
using finite semigroups as example to illustrate the process.The new implementation is as follows:
sets_cat_test.py
) defines generic tests that should pass for every object in that category. Moreover, the test class may provides instances (objects) to test via the methodcategory_instances
.finite_semigroups_test.py
, then determines the categories of the objects (returned fromcategory_instances
) and adds all generic test methods for that category to the test class (this happens inconftest.py
).category_instance
which is bound to the return value of thecategory_instances
method.Running
cd src && pytest --verbose
(from a virtual env with sage and pytest installed), the output is as follows:As one can see, each general test method is invoked for the three examples.
TODO (in follow-up tickets):
TestSuite
in doctests and remove theTestSuite
class.See also:
CC: @mkoeppe @tscrim @nthiery @slel
Component: refactoring
Keywords: testsuite
Author: Tobias Diez
Branch/Commit: public/refactoring/pytest @
b047abe
Issue created by migration from https://trac.sagemath.org/ticket/30738
The text was updated successfully, but these errors were encountered: