In the Python unittest framework, is there a way to pass a unit test if an exception wasn\'t raised, and fail with an AssertRaise otherwise?
unittest
Simply call your functionality, e.g. do_something(). If an unhandled exception gets raised, the test automatically fails! There is really no reason to do anything else. This is also the reason why assertDoesNotRaise() does not exist.
do_something()
assertDoesNotRaise()
Credit: comment by Sven