Skip to content

TST: avoid non-falsifiable matches (match='') in pytest.raises#17857

Merged
neutrinoceros merged 2 commits into
astropy:mainfrom
neutrinoceros:modeling/test/avoid_matching_empty_strings
Mar 11, 2025
Merged

TST: avoid non-falsifiable matches (match='') in pytest.raises#17857
neutrinoceros merged 2 commits into
astropy:mainfrom
neutrinoceros:modeling/test/avoid_matching_empty_strings

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

Description

Avoid an incoming warning in pytest 8.4 (dev)
Follow up to #13919

reprod

pip install git+https://github.com/pytest-dev/pytest scipy
pytest astropy/modeling/tests/test_models.py

output (truncated)

...
pytest.PytestWarning: matching against an empty string will *always* pass. If you want to check for an empty message you need to pass '^$'. If you don't want to match you should pass `None` or leave out the parameter.

xref pytest-dev/pytest#13192

  • 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

github-actions Bot commented Mar 6, 2025

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.

@pllim pllim added the testing label Mar 6, 2025
@neutrinoceros neutrinoceros changed the title TST: avoid non-falsifiable matches (match='') in pytest.raises TST: avoid non-falsifiable matches (`match='') in pytest.raises Mar 6, 2025
@neutrinoceros neutrinoceros changed the title TST: avoid non-falsifiable matches (`match='') in pytest.raises TST: avoid non-falsifiable matches (match='') in ˋpytest.raises` Mar 6, 2025
values = np.array([1.5, 3.4, 3.4, 32, 25])
t = models.Tabular1D(points, values)
with pytest.raises(NotImplementedError, match=r""):
with pytest.raises(NotImplementedError, match=r"^$"):
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.

Why match anything 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.

That would be a question for @WilliamJamieson. The intent from #13919 seems pretty clear that match should always be specified.

@neutrinoceros neutrinoceros changed the title TST: avoid non-falsifiable matches (match='') in ˋpytest.raises` TST: avoid non-falsifiable matches (match='') in pytest.raises Mar 6, 2025
@pllim pllim added the Extra CI Run cron CI as part of PR label Mar 6, 2025
@pllim
Copy link
Copy Markdown
Member

pllim commented Mar 6, 2025

Also why didn't the dev infra job catch this? 🤔

devinfra: git+https://github.com/pytest-dev/pytest.git

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

because it's not installing scipy and this specific test is skipped without it.

@pllim

This comment was marked as resolved.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

I'm not sure this fits the scope of this environment, but it is clear from this PR that it's a blind spot from our CI so... I guess I'm +0.
Would you like that I try it in this PR ?

@pllim
Copy link
Copy Markdown
Member

pllim commented Mar 6, 2025

Adding it in this PR would prove that your fixes indeed work, so doesn't hurt, especially since we're waiting for William's reply?

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

not sure how to proceed though. devinfra only seems to include extra dependencies directly from github (git+https://...), which will not work for scipy :/

@pllim

This comment was marked as outdated.

@pllim

This comment was marked as outdated.

@pllim

This comment was marked as resolved.

@pllim
Copy link
Copy Markdown
Member

pllim commented Mar 6, 2025

Thanks! Looks like devinfra installs scipy now and green here.

Copy link
Copy Markdown
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

I think this is reasonable patch, so even if we don't hear back from William, probably okay to merge. But maybe give him a few days? 🤷‍♀️

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

I'm going to merge it before my brain rewires itself to start ignoring this failure. @WilliamJamieson, please feel free to do a post-mortem review if you'd like. Happy to revisit if details need changes. Thanks !

@neutrinoceros neutrinoceros merged commit ac4d776 into astropy:main Mar 11, 2025
@neutrinoceros neutrinoceros deleted the modeling/test/avoid_matching_empty_strings branch March 11, 2025 17:08
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Mar 11, 2025
pllim added a commit that referenced this pull request Mar 11, 2025
…n `pytest.raises` (#17871)

Co-authored-by: Clément Robert <cr52@protonmail.com>
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.

2 participants