This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Addition of assertNotRaises
Type: enhancement Stage:
Components: Library (Lib), Tests Versions: Python 3.6
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: bar.harel, ezio.melotti, michael.foord, r.david.murray, rbcollins, rhettinger, steven.daprano
Priority: normal Keywords:

Created on 2016-06-01 14:16 by bar.harel, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg266816 - (view) Author: Bar Harel (bar.harel) * Date: 2016-06-01 14:16
I thought of implementing an assertNotRaises to solve the issue of using in order to prevent showing the tests as an error and instead show them as a failure.
Is there anything I should consider while implementing it?
msg266820 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-06-01 15:10
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.
msg266821 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-06-01 16:18
Agreed.  I've never used the distinction between errors and failures myself.
msg266824 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-06-01 16:43
I concur with David snd Steven, so closing this as rejected.
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71363
2016-06-01 16:43:05rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg266824

resolution: rejected
2016-06-01 16:18:07r.david.murraysetnosy: + r.david.murray
messages: + msg266821
2016-06-01 15:10:28steven.dapranosetnosy: + steven.daprano
messages: + msg266820
2016-06-01 14:31:38SilentGhostsetnosy: + rbcollins, ezio.melotti, michael.foord

versions: + Python 3.6
2016-06-01 14:16:56bar.harelcreate