5.3.4 Classes and functions

class TestCase( )
Instances of the TestCase class represent the smallest testable units in a set of tests. This class is intended to be used as a base class, with specific tests being implemented by concrete subclasses. This class implements the interface needed by the test runner to allow it to drive the test, and methods that the test code can use to check for and report various kinds of failures.

class FunctionTestCase( testFunc[, setUp[, tearDown[, description]]])
This class implements the portion of the TestCase interface which allows the test runner to drive the test, but does not provide the methods which test code can use to check and report errors. This is used to create test cases using legacy test code, allowing it to be integrated into a unittest-based test framework.

class TestSuite( [tests])
This class represents an aggregation of individual tests cases and test suites. The class presents the interface needed by the test runner to allow it to be run as any other test case, but all the contained tests and test suites are executed. Additional methods are provided to add test cases and suites to the aggregation. If tests is given, it must be a sequence of individual tests that will be added to the suite.

class TestLoader( )
This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite. It can load all tests within a given module or TestCase class. When loading from a module, it considers all TestCase-derived classes. For each such class, it creates an instance for each method with a name beginning with the string "test".

Instance of the TestLoader class which can be shared. If no customization of the TestLoader is needed, this instance can always be used instead of creating new instances.

class TextTestRunner( [stream[, descriptions[, verbosity]]])
A basic test runner implementation which prints results on standard output. It has a few configurable parameters, but is essentially very simple. Graphical applications which run test suites should provide alternate implementations.

main( [module[, defaultTest[, argv[, testRunner[, testRunner]]]]])
A command-line program that runs a set of tests; this is primarily for making test modules conveniently executable. The simplest use for this function is:

if __name__ == '__main__':

In some cases, the existing tests may have be written using the doctest module. If so, that module provides a DocTestSuite class that can automatically build unittest.TestSuite instances from the existing test code. New in version 2.3.

See About this document... for information on suggesting changes.