Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:5.3.5 TestSuite ObjectsUp:5.3 unittestNext:5.3.7 TestLoader Objects

 
5.3.6 TestResult Objects

ATestResult object stores the results of a set of tests. TheTestCase andTestSuite classes ensure that results areproperly stored; test authors do not need to worry about recording theoutcome of tests.

Testing frameworks built on top ofunittest may wantaccess to theTestResult object generated by running a set oftests for reporting purposes; aTestResult instance isreturned by theTestRunner.run() method for this purpose.

Each instance holds the total number of tests run, and collections offailures and errors that occurred among those test runs. Thecollections contain tuples of(testcase,traceback), wheretraceback is a string containing aformatted version of the traceback for the exception.

TestResult instances have the following attributes that willbe of interest when inspecting the results of running a set of tests:

errors
A list containing pairs ofTestCase instances and the formatted tracebacks for tests which raised an exception but did not signal a test failure.Changed in version 2.2:Contains formatted tracebacks instead ofsys.exc_info() results.

failures
A list containing pairs ofTestCase instances and the formatted tracebacks for tests which signalled a failure in the code under test.Changed in version 2.2:Contains formatted tracebacks instead ofsys.exc_info() results.

testsRun
The number of tests which have been started.

wasSuccessful()
Returns true if all tests run so far have passed, otherwise returns false.

The following methods of theTestResult class are used tomaintain the internal data structures, and mmay be extended insubclasses to support additional reporting requirements. This isparticularly useful in building tools which support interactivereporting while tests are being run.

startTest(test)
Called when the test casetest is about to be run.

stopTest(test)
Called when the test casetest has been executed, regardless of the outcome.

addError(test, err)
Called when the test casetest raises an exception without signalling a test failure.err is a tuple of the form returned bysys.exc_info():(type,value,traceback).

addFailure(test, err)
Called when the test casetest signals a failure.err is a tuple of the form returned bysys.exc_info():(type,value,traceback).

addSuccess(test)
This method is called for a test that does not fail;test is the test case object.

One additional method is available forTestResult objects:

stop()
This method can be called to signal that the set of tests being run should be aborted. Once this has been called, theTestRunner object return to its caller without running any additional tests. This is used by theTextTestRunner class to stop the test framework when the user signals an interrupt from the keyboard. Interactive tools which provide runners can use this in a similar manner.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:5.3.5 TestSuite ObjectsUp:5.3 unittestNext:5.3.7 TestLoader Objects
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp