Skip to content

Conversation

tobiasdiez
Copy link
Contributor

@tobiasdiez tobiasdiez commented Jul 19, 2025

Pytest used to run on as part of sage -t, but this is no longer the case. Here, we reactivate it by removing some safe-guards that are no longer necessary as pytest is a standard package now.

Moreover, a "runtime error" due to a changing dict in an iteration is fixed in ae60cda.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@tobiasdiez
Copy link
Contributor Author

No idea about the failing tests in test-long....

@orlitzky
Copy link
Contributor

I guess the CI is invoking pytest via the ./sage script and a doctest wrapper? I was just typing pytest like a crazy person.

@tobiasdiez
Copy link
Contributor Author

I guess the CI is invoking pytest via the ./sage script and a doctest wrapper? I was just typing pytest like a crazy person.

Yes, pytest is called as part of sage -t (that was supposed to work already). I don't get the test failures in dev_tools.py - they seem to be unrelated.

@user202729
Copy link
Contributor

Maybe you should retrigger the CI (e.g. by pushing an empty commit) just in case.

@tobiasdiez
Copy link
Contributor Author

Maybe you should retrigger the CI (e.g. by pushing an empty commit) just in case.

15f17bb is almost such an empty commit but didn't fix it. I've now opened #40474 for a minimally invasive solution.

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 1, 2025
sagemathgh-40474: Add pytest command to run tests in CI workflow
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Alternative to sagemath#40446. This time
running pytest directly in the CI, instead of as part of `sage -t`.

Removed one old test file that fails with meson since the sage cli is
different then.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#40474
Reported by: Tobias Diez
Reviewer(s):
Copy link

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

@tobiasdiez tobiasdiez changed the title Run pytest again on CI Reenable pytest again as part of sage -t Sep 28, 2025
@tobiasdiez
Copy link
Contributor Author

This is now finally working. @user202729 @orlitzky please have a look.

(CI now actually runs the pytests twice: once as we call pytest directly, and once as part of sage -t. This shouldn't be a big issue as the tests complete in very short time. And it makes sure that the pytests are still working even when run from the sage env, so this should give additional security in the setup.)

@user202729
Copy link
Contributor

user202729 commented Sep 28, 2025

Hm… I'm not entirely sure what this does, it would be useful to explain what exactly does pytest run on. (methods start with test_ in the file? doctests? methods start with test_ in the whole repository?)

Though it's probably better to answer this in a docstring or rst file edit instead of a comment.

@tobiasdiez
Copy link
Contributor Author

tobiasdiez commented Sep 30, 2025

It's the same as running pytest directly. So, essentially _test.py files and then method with test_ therein.

This PR also doesn't introduce anything new. The functionality to run pytest as part of sage -t is there for some time, it just got broken/disabled by moving conftest.py to the root directory.

@user202729
Copy link
Contributor

I'm not entirely sure that's the right thing to do. Previously sage -t a.py runs doctest in a.py, now it runs doctest in a.py plus *_test.py file in the whole sage directory? At least if it runs a_test.py only I'd call it reasonable.

Plus does it work only from sage root, or any directory?

@tobiasdiez
Copy link
Contributor Author

tobiasdiez commented Sep 30, 2025

I'm not entirely sure that's the right thing to do. Previously sage -t a.py runs doctest in a.py, now it runs doctest in a.py plus *_test.py file in the whole sage directory? At least if it runs a_test.py only I'd call it reasonable.

Yes only _test files are passed on to pytest if you specify a file. To cite from the code:

        # Do not run pytest on individual Python files unless
        # they match the pytest file pattern.  However, pass names
        # of directories.

@orlitzky
Copy link
Contributor

orlitzky commented Oct 5, 2025

The dev_tools.py error must have something to do with pytest, I also had to fix it in #40971 to get the CI to pass.

# they match the pytest file pattern. However, pass names
# of directories. We use 'not os.path.isfile(f)' for this so that
# we do not silently hide typos.
filenames = [f for f in args.filenames
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cute but we should probably use os.path.isdir() or not os.path.exists().

@orlitzky
Copy link
Contributor

orlitzky commented Oct 5, 2025

Aside from that one small refactoring for clarity, this LGTM, but I'm not sure if we should keep the separate pytest CI job. I've been moving slow doctests to pytest, and as they accumulate, it's going to become less and less reasonable to re-run several minutes' worth of tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants