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.

Get Scientific Computing with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.