Skip to content

Conversation

@orlitzky
Copy link
Contributor

There are two files, src/sage/libs/gap/test{,_long}.py that contain only tests for sage.libs.gap. These are doctests for no other reason than because we had no other way to run them in the past. This commit moves them to a new file, gap_test.py, that will be run by pytest rather than the doctest runner.

In the process I've tried to explain what I think the tests are doing.



@pytest.fixture
def tmpfile():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there nothing existing like this in pytest/sage? This feels oddly general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest has a built-in tmpdir that does almost the same thing, but with a directory instead of a file. But considering pytest-dev/pytest#13669, this is safer for now.

Copy link
Contributor

@user202729 user202729 Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any other place fixtures such as this can be placed (conftest?) We will have to eventually move it there once the same fixture is needed in another module's test anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conftest.py works, done.


def test_gc_loop_1():
r"""
First stress test for garbage collection in libgap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel "[[first]] stress test" is highly redundant, mostly because there shouldn't be any need to modify the docstring if we want to reorder the tests or add something inbetween.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted "First", "Second", and "Third" from the docstrings. There's still a number in the function name, but I don't know what else to call them.

result = True
for i in range(300000):
n = libgap.Order(H1)
result |= (n == two)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely you mean &=. Still, it feels like bad practice to use bitwise operator for boolean. What about just assert n == two each time here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that first but then pytest -v prints OK three hundred thousand times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The &= is fixed, thanks.)

lis.Add(a ** 2)
lis.Add(b ** 2)
lis.Add(b * a)
assert True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this assert useless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test did essentially the same thing. I can only assume that it's an "it doesn't segfault" test.

There are two files, src/sage/libs/gap/test{,_long}.py that contain
only tests for sage.libs.gap. These are doctests for no other reason
than because we had no other way to run them in the past. This commit
moves them to a new file, gap_test.py, that will be run by pytest
rather than the doctest runner.

In the process I've tried to explain what I think the tests are doing.
@user202729
Copy link
Contributor

sanity check, is pytest currently run on CI?

If yes, approve if tests pass.

@orlitzky
Copy link
Contributor Author

sanity check, is pytest currently run on CI?

If yes, approve if tests pass.

Should be, since #40474

A temporary file that is deleted after the test has completed will be
useful elsewhere.
These have been moved to pytest (gap/gap_test.py).
@github-actions
Copy link

Documentation preview for this PR (built with commit 1b56421; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@orlitzky
Copy link
Contributor Author

CI fails are the usual suspects. Marking positive review, thanks.

@tobiasdiez
Copy link
Contributor

Nice, thanks a lot. I'm happy to see that there is finally a bit more interest in pytest 🦊

vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 1, 2025
There are two files, `src/sage/libs/gap/test{,_long}.py` that contain
only tests for `sage.libs.gap`. These are doctests for no other reason
than because we had no other way to run them in the past. This commit
moves them to a new file, `gap_test.py`, that will be run by pytest
rather than the doctest runner.

In the process I've tried to explain what I think the tests are doing.

URL: sagemath#40677
Reported by: Michael Orlitzky
Reviewer(s): Michael Orlitzky, user202729
@vbraun vbraun merged commit e9f3727 into sagemath:develop Sep 7, 2025
24 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants