-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-91230: Concise catch_warnings with simplefilter #91435
gh-91230: Concise catch_warnings with simplefilter #91435
Conversation
Misc/NEWS.d/next/Library/2022-04-10-17-12-23.gh-issue-91230.T1d_fG.rst
Outdated
Show resolved
Hide resolved
3bac2a9
to
2098a68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea and implementation look solid.
2098a68
to
f7056ea
Compare
Thanks @JelleZijlstra for your review! I've updated the docs accordingly; let me know if there's anything else 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed one more thing while re-reviewing.
Closes #91230, which was in turn motivated by pytest-dev/pytest#9404 (comment) and pytest-dev/pytest#9745 (comment): users evidently want a concise context manager to ignore all warnings in some block of code, and to error on warnings on some block of code.
Of course that can be done with the standard library
with warnings.catch_warnings():
pluswarnings.simplefilter(...)
; but in practice this is quite rare. I believe that the trivial friction of needing two statements plays a substantial role here, and therefore thatwith warnings.catch_warnings(action="error"):
(oraction="ignore"
) would be a substantial win for many people, especially in tests.I've specifically chosen
simplefilter
overfilterwarnings
because the latter has a conflictingmodule
parameter.