I want to check for an exception in Python unittest, with the following requirements:
- Needs to be reported as a failure, NOT an error
- Must not swallow the original exception
I've seen lots of solutions of the form:
try:
something()
except:
self.fail("It failed")
Unfortunately these solutions swallow the original exception. Any way to retain the original exception?
I ended up using a variant of Pierre GM's answer:
try:
something()
except:
self.fail("Failed with %s" % traceback.format_exc())