Skip to content
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

Do not make use of pytest.warns(None) #868

Merged

Conversation

s-t-e-v-e-n-k
Copy link

pytest.warns(None) is an anti-pattern, and there are easier ways to accomplish both cases with how the code is leveraging pytest.warns(). Firstly, it can match on a specific warning and will assert that the warning is raised -- and it doesn't need to be used if we want to assert code raises no warnings, the standard library can do that directly. Furthermore, pytest.warns(None) is an error in Pytest 8 and above.

@clintonsteiner
Copy link
Collaborator

This is no longer needed due to similar test fixes which have been merged

@s-t-e-v-e-n-k
Copy link
Author

with warnings.catch_warnings() is not sufficient, since it will swallow any warnings emitted, which is not what the test case is trying to accomplish. Setting the warnings filter to error will raise them as exceptions, like so:

with warnings.catch_warnings():
            warnings.simplefilter("error")

I'm happy to rebase this PR to just make that change.

@clintonsteiner
Copy link
Collaborator

Good callout, please do so

One test case after the transition from pytest.warns(None) is attempting
to check it raises no warnings, but as written the context manager
swallows all warnings. Set the filter to error to make certain they are
raised.
@s-t-e-v-e-n-k s-t-e-v-e-n-k force-pushed the no-more-pytest-warns-None branch from 3c11258 to a416c80 Compare January 9, 2025 01:20
@s-t-e-v-e-n-k
Copy link
Author

I've rebased, made that one line change and rewritten the commit message (but not the PR description/title)

@clintonsteiner clintonsteiner merged commit 3a9510a into pycontribs:master Jan 9, 2025
8 checks passed
@clintonsteiner
Copy link
Collaborator

thank you @s-t-e-v-e-n-k

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.

2 participants