The python unittest runner handles all exceptions. I would like to catch them with my debugger.
Is there a way to make my unittest runner re-raise tests exceptions to terminate the process? I want to handle them myself.
Edit: Found a solution.
You can create a unittest.TestSuite and call debug() to run the tests you want to debug - including catching the exceptions with your debugger!
It can be easily done with this pattern:
import unittest
class DebuggableTestCase(unittest.TestCase):
@classmethod
def debugTestCase(cls):
loader = unittest.defaultTestLoader
testSuite = loader.loadTestsFromTestCase(cls)
testSuite.debug()
class MyTestCase(DebuggableTestCase):
def test_function_that_fails(self):
raise Exception('test')
if __name__ == '__main__':
MyTestCase.debugTestCase()