A few times now I've seen people write something that overrides and re-implements the unittest.TestCase run() method, copying most of the implementation but adding one feature:
The ability for pdb.post_mortem() to be called after every phase of execution iff an exception/error was caught (setUp(), the testMethod() call itself and tearDown()).
I really hate seeing people have to copy the run method implementation and modify it.
We could support this either by adding another debugHook() method to the TestCase API. Proposal: it gets called within the except: clause surrounding each phase of test execution.
Turning on support for automatic pdb.post_mortem(), typically controlled via a flag or other environment configurable as it isn't desirable during automation:
def debugHook(self):
if SOMETHING_SAYS_TO_ENABLE_THIS:
pdb.post_mortem()
no more copy and pasting the run() method. |