msg115434 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 10:50 |
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. |
|
|
msg115436 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2010-09-03 11:04 |
+1 |
|
|
msg115449 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 12:44 |
The __warningregistry__ stuff looks horrible. |
|
|
msg115450 - (view) |
Author: Florent Xicluna (flox) *  |
Date: 2010-09-03 12:51 |
> unittest should provide assertWarns and assertWarnsRegexp +1 (the internal helpers in test.support could be refactored) > The __warningregistry__ stuff looks horrible. +1 (and it does not behave exactly the same in all Python versions) |
|
|
msg115451 - (view) |
Author: Giampaolo Rodola' (giampaolo.rodola) *  |
Date: 2010-09-03 12:55 |
+1 from me as well. |
|
|
msg115453 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 13:59 |
Here is a patch. The approach is different from support.check_warnings(), and tries to mimic assertRaises* instead. |
|
|
msg115455 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 14:13 |
There was some dead code in the patch. |
|
|
msg115460 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2010-09-03 15:19 |
(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.) |
|
|
msg115465 - (view) |
Author: Florent Xicluna (flox) *  |
Date: 2010-09-03 16:45 |
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? (With assertRaises we don't have such use case) |
|
|
msg115469 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 17:05 |
> 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. That would be at the expense of removing the "callable" argument (and mandating the use as a context manager), though, otherwise the signature gets too complicated. |
|
|
msg115470 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2010-09-03 17:08 |
Why not accepting a tuple of warnings? That doesn't make sense for assertWarnsRegexp of course. |
|
|
msg115471 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-03 17:12 |
> Why not accepting a tuple of warnings? It already does (and there's a test!). > That doesn't make sense for assertWarnsRegexp of course. True. |
|
|
msg115614 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-04 20:33 |
Updated patch so that the tests pass with -Werror. Do you think this should be committed before the next alpha? |
|
|
msg115730 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2010-09-06 19:26 |
Committed in r84563! |
|
|