Debugging
Debugging is sometimes necessary while testing, in particular if it is not immediately clear why a given test does not pass. In that case, it is useful to be able to debug a given test in an interactive session. This is however, made difficult by the design of the unittest.TestCase
class, which prevents easy instantiation of test case objects. The solution is to create a special instance for debugging purpose only.
Suppose that, in the example of the TestIdentity
class above, we want to test the test_functionality
method. This would be achieved as follows:
test_case = TestIdentity(methodName='test_functionality')
Now this test can be run individually by:
test_case.debug()
This will run this individual test and it allows for debugging.