class documentation

A basic TestResult with support for writing to a stream.

Method __init__ Undocumented
Method addError Called when a test raises an error. If realtime is set, then it prints the error to the stream.
Method addFailure Called when a test fails. If realtime is set, then it prints the error to the stream.
Method cleanupErrors Undocumented
Method done Summarize the result of the test run.
Method startTest Called when a test begins to run. Records the time when it was first called and resets the warning cache.
Method upDownError Undocumented
Instance Variable realtime Undocumented
Instance Variable tbformat Undocumented
Method _formatFailureTraceback Undocumented
Method _getSummary Return a formatted count of tests status results.
Method _groupResults Group tests together based on their results.
Method _observeWarnings Observe warning events and write them to self._stream.
Method _printErrors Print all of the non-success results to the stream in full.
Method _printExpectedFailure Undocumented
Method _printResults Print a group of errors to the stream.
Method _printSummary Print a line summarising the test results to the stream.
Method _printUnexpectedSuccess Undocumented
Method _trimFrames Trim frames to remove internal paths.
Method _write Safely write to the reporter's stream.
Method _writeln Safely write a line to the reporter's stream. Newline is appended to the format string.
Class Variable _doubleSeparator Undocumented
Class Variable _separator Undocumented
Instance Variable _publisher The log publisher which will be observed for warning events.
Instance Variable _startTime The time when the first test was started. It defaults to None, which means that no test was actually launched.
Instance Variable _stream Undocumented
Instance Variable _warningCache A set of tuples of warning message (file, line, text, category) which have already been written to the output stream during the currently executing test. This is used to avoid writing duplicates of the same warning to the output stream.

Inherited from TestResult:

Method __repr__ Undocumented
Method addExpectedFailure Report that the given test failed, and was expected to do so.
Method addSkip Report that the given test was skipped.
Method addSuccess Report that the given test succeeded.
Method addUnexpectedSuccess Report that the given test succeeded against expectations.
Method stopTest This must be called after the given test is completed.
Method wasSuccessful Report whether or not this test suite was successful or not.
Instance Variable expectedFailures Undocumented
Instance Variable skips Undocumented
Instance Variable successes count the number of successes achieved by the test run.
Instance Variable unexpectedSuccesses Undocumented
Method _getFailure Convert a sys.exc_info()-style tuple to a Failure, if necessary.
Method _getTime Undocumented
Constant _DEFAULT_TODO Undocumented
Instance Variable _lastTime The duration of the current test run. It defaults to None, which means that the test was skipped.
Instance Variable _testStarted Undocumented
Instance Variable _timings Undocumented
def __init__(self, stream=sys.stdout, tbformat='default', realtime=False, publisher=None): (source)
def addError(self, test, error): (source)

Called when a test raises an error. If realtime is set, then it prints the error to the stream.

Parameters
testITestCase that raised the error.
errorfailure.Failure containing the error.
def addFailure(self, test, fail): (source)

Called when a test fails. If realtime is set, then it prints the error to the stream.

Parameters
testITestCase that failed.
failfailure.Failure containing the error.
def cleanupErrors(self, errs): (source)

Undocumented

def done(self): (source)

Summarize the result of the test run.

The summary includes a report of all of the errors, todos, skips and so forth that occurred during the run. It also includes the number of tests that were run and how long it took to run them (not including load time).

Expects that _printErrors, _writeln, _write, _printSummary and _separator are all implemented.

def startTest(self, test): (source)

Called when a test begins to run. Records the time when it was first called and resets the warning cache.

Parameters
testITestCase
def upDownError(self, method, error, warn=True, printStatus=True): (source)

Undocumented

realtime = (source)

Undocumented

tbformat = (source)

Undocumented

def _formatFailureTraceback(self, fail): (source)

Undocumented

def _getSummary(self): (source)

Return a formatted count of tests status results.

def _groupResults(self, results, formatter): (source)

Group tests together based on their results.

Parameters
resultsAn iterable of tuples of two or more elements. The first element of each tuple is a test case. The remaining elements describe the outcome of that test case.
formatterA callable which turns a test case result into a string. The elements after the first of the tuples in results will be passed as positional arguments to formatter.
Returns
A list of two-tuples. The first element of each tuple is a unique string describing one result from at least one of the test cases in results. The second element is a list of the test cases which had that result.
def _observeWarnings(self, event): (source)

Observe warning events and write them to self._stream.

This method is a log observer which will be registered with self._publisher.addObserver.

Parameters
eventA dict from the logging system. If it has a 'warning' key, a logged warning will be extracted from it and possibly written to self.stream.
def _printErrors(self): (source)

Print all of the non-success results to the stream in full.

def _printExpectedFailure(self, error, todo): (source)

Undocumented

def _printResults(self, flavor, errors, formatter): (source)

Print a group of errors to the stream.

Parameters
flavorA string indicating the kind of error (e.g. 'TODO').
errorsA list of errors, often failure.Failures, but sometimes 'todo' errors.
formatterA callable that knows how to format the errors.
def _printSummary(self): (source)

Print a line summarising the test results to the stream.

def _printUnexpectedSuccess(self, todo): (source)

Undocumented

def _trimFrames(self, frames): (source)

Trim frames to remove internal paths.

When a SynchronousTestCase method fails synchronously, the stack looks like this:

  • [0]: SynchronousTestCase._run
  • [1]: util.runWithWarningsSuppressed
  • [2:-2]: code in the test method which failed
  • [-1]: _synctest.fail

When a TestCase method fails synchronously, the stack looks like this:

  • [0]: defer.maybeDeferred
  • [1]: utils.runWithWarningsSuppressed
  • [2]: utils.runWithWarningsSuppressed
  • [3:-2]: code in the test method which failed
  • [-1]: _synctest.fail

When a method fails inside a Deferred (i.e., when the test method returns a Deferred, and that Deferred's errback fires), the stack captured inside the resulting Failure looks like this:

  • [0]: defer.Deferred._runCallbacks
  • [1:-2]: code in the testmethod which failed
  • [-1]: _synctest.fail

As a result, we want to trim either [maybeDeferred, runWWS, runWWS] or [Deferred._runCallbacks] or [SynchronousTestCase._run, runWWS] from the front, and trim the [unittest.fail] from the end.

There is also another case, when the test method is badly defined and contains extra arguments.

If it doesn't recognize one of these cases, it just returns the original frames.

Parameters
framesThe list of frames from the test failure.
Returns
The list of frames to display.
def _write(self, format, *args): (source)

Safely write to the reporter's stream.

Parameters
formatA format string to write.
*argsThe arguments for the format string.
def _writeln(self, format, *args): (source)

Safely write a line to the reporter's stream. Newline is appended to the format string.

Parameters
formatA format string to write.
*argsThe arguments for the format string.
_doubleSeparator = (source)

Undocumented

_separator = (source)

Undocumented

The log publisher which will be observed for warning events.

_startTime: float or None = (source)

The time when the first test was started. It defaults to None, which means that no test was actually launched.

Undocumented

_warningCache: set = (source)

A set of tuples of warning message (file, line, text, category) which have already been written to the output stream during the currently executing test. This is used to avoid writing duplicates of the same warning to the output stream.