I want to write a test to establish that an Exception is not raised in a given circumstance.
It\'s straightforward to test if an Exception is raise
def _assertNotRaises(self, exception, obj, attr):
try:
result = getattr(obj, attr)
if hasattr(result, '__call__'):
result()
except Exception as e:
if isinstance(e, exception):
raise AssertionError('{}.{} raises {}.'.format(obj, attr, exception))
could be modified if you need to accept parameters.
call like
self._assertNotRaises(IndexError, array, 'sort')