A TestResult object stores the results of a set of tests. The TestCase and TestSuite classes ensure that results are properly recorded; test authors do not need to worry about recording the outcome of tests.
Testing frameworks built on top of unittest may want access to the TestResult object generated by running a set of tests for reporting purposes; a TestResult instance is returned by the TestRunner.run() method for this purpose.
TestResult instances have the following attributes that will be of interest when inspecting the results of running a set of tests:
) |
) |
shouldStop
attribute to True. TestRunner objects should respect
this flag and return without running any additional tests.
For example, this feature is used by the TextTestRunner class to stop the test framework when the user signals an interrupt from the keyboard. Interactive tools which provide TestRunner implementations can use this in a similar manner.
The following methods of the TestResult class are used to maintain the internal data structures, and may be extended in subclasses to support additional reporting requirements. This is particularly useful in building tools which support interactive reporting while tests are being run.
test) |
The default implementation simply increments the instance's
testsRun
counter.
test) |
The default implementation does nothing.
test, err) |
(type, value, traceback)
.
The default implementation appends (test, err)
to
the instance's errors
attribute.
test, err) |
(type, value,
traceback)
.
The default implementation appends (test, err)
to
the instance's failures
attribute.
test) |
The default implementation does nothing.
See About this document... for information on suggesting changes.