Skip to content

TST: use --strict-markers when running pytest with --pyargs#18890

Merged
neutrinoceros merged 1 commit intoastropy:mainfrom
neutrinoceros:tst/strict-pytest-markers-pyargs
Nov 13, 2025
Merged

TST: use --strict-markers when running pytest with --pyargs#18890
neutrinoceros merged 1 commit intoastropy:mainfrom
neutrinoceros:tst/strict-pytest-markers-pyargs

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

Description

extracted from #18784.
Enabling this option makes a tremendous difference in debugging the kind of problems I'm hitting in that PR.
In brief, --pyargs astropy is used to test an installed package in place, so any test marker defined in the repo-level conftest.py is undefined. By default, pytest warns about such markers, but doesn't raise. The --strict-markers flag requires that all markers are defined.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions
Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

This isn't critical yet, but I suggest backporting it any way. Any difference that this could make would be an error we want to know about.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

also note that --strict-markers is already on our addopts options, but because pyproject.toml is also not discovered when running via --pyargs, it still needs to be set on the CLI

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

I also needed to replace -p no:warnings, which deactivates the (builtin) pytest plugin that defines @pytest.mark.filterwarnings, with -Wignore, which I think corresponds to the intended behavior, but avoids this issue.

@neutrinoceros neutrinoceros force-pushed the tst/strict-pytest-markers-pyargs branch from db76e36 to 89b3bbf Compare November 12, 2025 08:52
@neutrinoceros neutrinoceros added the Extra CI Run cron CI as part of PR label Nov 12, 2025
@neutrinoceros
Copy link
Copy Markdown
Contributor Author

failures are unrelated and already handled in dedicated PRs. However, I would feel much more confortable undrafting this with green CI (or at least a single unrelated failure mode), so I'll wait for other fixes to get merged first.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

On the other hand, we're having so many issues at the same time that I fear creating a deadlock instead of a queue, so let's undraft this now since none of the failures appear relevant.

@neutrinoceros neutrinoceros marked this pull request as ready for review November 12, 2025 11:52
@neutrinoceros neutrinoceros requested a review from saimn as a code owner November 12, 2025 12:20
@neutrinoceros neutrinoceros force-pushed the tst/strict-pytest-markers-pyargs branch 2 times, most recently from 7055592 to a5c6b90 Compare November 12, 2025 14:28
upload_to_anaconda: false
test_extras: test
test_command: pytest -p no:warnings --astropy-header -m "not hypothesis" -k "not test_data_out_of_range and not test_set_locale and not TestQuantityTyping" --pyargs astropy
test_command: pytest -Wdefault --astropy-header -m "not hypothesis" -k "not test_data_out_of_range and not test_set_locale and not TestQuantityTyping" --strict-markers --pyargs astropy
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is -Wdefault exactly the same as -p no:warnings?

Copy link
Copy Markdown
Contributor Author

@neutrinoceros neutrinoceros Nov 12, 2025

Choose a reason for hiding this comment

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

no. If it was, I wouldn't need to change the existing code.
-p no:warnings completely disables warning control from pytest, including making filterwarnings decorators noop (undefined). I assume the real intention is instead to override our settings, which notably include filterwarnings: error, and this is what-Wdefault does.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But where is the "default" defined? I just want to make sure we won't get sudden failures in the jobs we thought we're ignoring warnings at future release time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's actually a flag from the python interpreter, conveniently re-exposed in pytest. The definition is at https://docs.python.org/3/library/warnings.html#the-warnings-filter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the default behavior is to let warnings be warnings instead of errors. They'll show up, but won't be blocking. In contrast, -p no:warnings hides them completely, which could be argued isn't desirable in CI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Depends... when you look at build logs, you just want to know wheels were made and tested. For those cases, printing out warnings will just clutter the logs. But let's see what @astrofrog says.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we really want to ignore them, -Wignore would be the closest, strict mode friendly, equivalent. It's actually what I used originally before it occurred to me that warnings are valuable data...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well... in our case, they are all handled in normal settings, so when we pass alternate flag, it means we don't care. 🤷‍♀️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it could still be valuable to see warnings that pop specifically in cibuildwheel. If any, these would likely be warnings from pytest itself, and it'd be helpful to see them to debug anything they would be warning about

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My assumption is that these logs are rarely consulted, but if I were to need them, I wouldn't want warnings to disappear (or have to remember that they are silenced, that alone could waste me hours of scratching my head in the long run)

@pllim pllim added the Build all wheels Run all the wheel builds rather than just a selection label Nov 12, 2025
Copy link
Copy Markdown
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks good but one small comment below

line syntax:

python -Wignore yourscript.py
python -Wdefault yourscript.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should revert the changes to this file, it's a historical document and doesn't need to be up to date

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, good catch. It wasn't intended at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted

@neutrinoceros neutrinoceros force-pushed the tst/strict-pytest-markers-pyargs branch from a5c6b90 to 2fac1a4 Compare November 13, 2025 11:56
@neutrinoceros neutrinoceros merged commit 656917b into astropy:main Nov 13, 2025
51 checks passed
@neutrinoceros neutrinoceros deleted the tst/strict-pytest-markers-pyargs branch November 13, 2025 13:28
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Nov 13, 2025
neutrinoceros added a commit to meeseeksmachine/astropy that referenced this pull request Nov 14, 2025
neutrinoceros added a commit to meeseeksmachine/astropy that referenced this pull request Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v7.2.x on-merge: backport to v7.2.x Build all wheels Run all the wheel builds rather than just a selection Extra CI Run cron CI as part of PR no-changelog-entry-needed Release testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants