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 class unittest.TestCase, which prevents easy instantiation of test case objects. The solution is to create a special instance for debugging purposes only.
Suppose that, in the previous example of the class TestIdentity, we want to test the method test_functionality. This would be achieved as follows:
test_case = TestIdentity(methodName='test_functionality')
Now this test can be run individually with:
test_case.debug()
This will run this individual test and it allows for debugging.