[pytest-dev] how to fail on exceptions in other threads and destructors
Nikolaus at rath.org
Sat Jun 1 23:41:44 CEST 2013
I would like to make sure that a test fails when it results in an
uncaught exception - even if the exception happens in a destructor or in
a separate thread.
What's the best way to do this?
My idea is to modify sys.excepthook such that it keeps a list of all the
exceptions encountered during a test run. Then, at the end of every
test, I could check this list and raise an exception if there were any
calls to sys.excepthook.
However, I'm not quite sure how to do this properly without having to
request an explicit fixture in every test. Is there a way to have
initialization and finalization code run for every test function? And
what kind of exception would I need to raise in the finalization code
for py.test to recognize that it is the test that failed (rather than a
bug in the finalization code)?
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the Pytest-dev