[issue27176] Addition of assertNotRaises

Steven D'Aprano report at bugs.python.org
Wed Jun 1 11:10:28 EDT 2016


Steven D'Aprano added the comment:

Yes. What does such an assertion actually mean?

Why would I write `self.assertNotRaises(ValueError, spam, arg)` rather than just call `spam(arg)`? The only difference is that assertNotRaises will treat one specific exception as a test failure rather than a error, but I don't think that's useful. spam(arg) presumably is supposed to return something, or do something, not merely "don't raise ValueError". Raising ValueError should be no different from raising any other exception: it's a error, not a failure.

It makes sense to test for expected exceptions. I don't think it makes sense to test for exceptions that don't happen. Every single successful test of `spam(arg)` shows that ValueError is not raised, as well as every imaginable other exception. I don't think there is any need for an assert method to test for exceptions not being raised.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27176>
_______________________________________


More information about the Python-bugs-list mailing list