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
assertWarns and assertWarnsRegexp #53963
Comments
Similar to assertRaises and assertRaisesRegexp, unittest should provide assertWarns and assertWarnsRegexp, to check that a given callable (or piece of code) triggers a particular warning. Currently, you have to do that manually using a mixture of warnings.catch_warnings and warnings.filterwarnings, which is pretty annoying. |
+1 |
The __warningregistry__ stuff looks horrible. |
+1
+1 |
+1 from me as well. |
Here is a patch. The approach is different from support.check_warnings(), and tries to mimic assertRaises* instead. |
There was some dead code in the patch. |
(Note that in general I am against extending the TestCase API with more asserts given how wide it is and how much it has expanded in recent versions. I've written warning checking code enough times for third party projects that I think this is worth it though.) |
Patch looks good. However tests do not pass with -Werror (while test_warnings and others pass). Is there a way to catch multiple warnings on a single logical line? |
I thought we could beef up the API with additional arguments. |
Why not accepting a tuple of warnings? That doesn't make sense for assertWarnsRegexp of course. |
It already does (and there's a test!).
True. |
Updated patch so that the tests pass with -Werror. |
Committed in r84563! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: