Creating reusable module code coverage tests

A good unit testing framework will allow not just the creation of tests for members of code elements, but will also provide mechanisms for executing code before any of the tests are run, as well as after all tests have executed, successfully or not. Python's unittest module handles that in the individual TestCase classes, which allow the class to implement the setUpClass and tearDownClass methods to handle the pre- and post-test setup and teardown, respectively.

That, then, means that it'd be possible to create a test class that could be imported, extended with module-specific properties, and added to a test module that could leverage all of the capabilities just shown to do the following:

Get Hands-On Software Engineering with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.