[New-bugs-announce] [issue14403] unittest module: provide inverse of "assertRaises"
report at bugs.python.org
Sun Mar 25 13:43:52 CEST 2012
New submission from Danilo Bargen <gezuru at gmail.com>:
Most assert statements of the unittest module provide both an assert statement as well as its inverse, like "assertIn" and "assertNotIn". There is apparently no such thing for exceptions.
I can do the following:
> with self.assertRaises(SomeException):
> with self.assertRaisesNot(SomeException):
I don't want to simply execute the code and hope that it doesn't raise an exception, because if it does, the test fails with an "error" status instead of a "failed" status.
A possible workaround is the following code:
> except SomeException:
But that is not that expressive as an assert statement.
A naming alternative would be "assertDoesNotRaise".
In case this enhancement gets accepted, there should also be an inverse of "assertRaisesRegexp".
title: unittest module: provide inverse of "assertRaises"
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce