Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
unittest.result.TestResult Class Reference
Inheritance diagram for unittest.result.TestResult:
Inheritance graph
[legend]
Collaboration diagram for unittest.result.TestResult:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def printErrors
def startTest
def startTestRun
def stopTest
def stopTestRun
def addError
def addFailure
def addSuccess
def addSkip
def addExpectedFailure
def addUnexpectedSuccess
def wasSuccessful
def stop
def __repr__

Public Attributes

 failfast
 failures
 errors
 testsRun
 skipped
 expectedFailures
 unexpectedSuccesses
 shouldStop
 buffer
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _setupStdout
def _restoreStdout
def _exc_info_to_string
def _is_relevant_tb_level
def _count_relevant_tb_levels

Private Attributes

 _stdout_buffer
 _stderr_buffer
 _original_stdout
 _original_stderr
 _mirrorOutput

Static Private Attributes

 _previousTestClass = None
 _testRunEntered = False
 _moduleSetUpFailed = False

Detailed Description

Holder for test result information.

Test results are automatically managed by the TestCase and TestSuite
classes, and do not need to be explicitly manipulated by writers of tests.

Each instance holds the total number of tests run, and collections of
failures and errors that occurred among those test runs. The collections
contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
formatted traceback of the error that occurred.

Definition at line 25 of file result.py.


Constructor & Destructor Documentation

def unittest.result.TestResult.__init__ (   self,
  stream = None,
  descriptions = None,
  verbosity = None 
)

Reimplemented in unittest.runner.TextTestResult.

Definition at line 39 of file result.py.

00039 
00040     def __init__(self, stream=None, descriptions=None, verbosity=None):
00041         self.failfast = False
00042         self.failures = []
00043         self.errors = []
00044         self.testsRun = 0
00045         self.skipped = []
00046         self.expectedFailures = []
00047         self.unexpectedSuccesses = []
00048         self.shouldStop = False
00049         self.buffer = False
00050         self._stdout_buffer = None
00051         self._stderr_buffer = None
00052         self._original_stdout = sys.stdout
00053         self._original_stderr = sys.stderr
00054         self._mirrorOutput = False

Here is the caller graph for this function:


Member Function Documentation

Definition at line 189 of file result.py.

00189 
00190     def __repr__(self):
00191         return ("<%s run=%i errors=%i failures=%i>" %
00192                (util.strclass(self.__class__), self.testsRun, len(self.errors),
00193                 len(self.failures)))
def unittest.result.TestResult._count_relevant_tb_levels (   self,
  tb 
) [private]

Definition at line 182 of file result.py.

00182 
00183     def _count_relevant_tb_levels(self, tb):
00184         length = 0
00185         while tb and not self._is_relevant_tb_level(tb):
00186             length += 1
00187             tb = tb.tb_next
00188         return length

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.result.TestResult._exc_info_to_string (   self,
  err,
  test 
) [private]
Converts a sys.exc_info()-style tuple of values into a string.

Definition at line 151 of file result.py.

00151 
00152     def _exc_info_to_string(self, err, test):
00153         """Converts a sys.exc_info()-style tuple of values into a string."""
00154         exctype, value, tb = err
00155         # Skip test runner traceback levels
00156         while tb and self._is_relevant_tb_level(tb):
00157             tb = tb.tb_next
00158 
00159         if exctype is test.failureException:
00160             # Skip assert*() traceback levels
00161             length = self._count_relevant_tb_levels(tb)
00162             msgLines = traceback.format_exception(exctype, value, tb, length)
00163         else:
00164             msgLines = traceback.format_exception(exctype, value, tb)
00165 
00166         if self.buffer:
00167             output = sys.stdout.getvalue()
00168             error = sys.stderr.getvalue()
00169             if output:
00170                 if not output.endswith('\n'):
00171                     output += '\n'
00172                 msgLines.append(STDOUT_LINE % output)
00173             if error:
00174                 if not error.endswith('\n'):
00175                     error += '\n'
00176                 msgLines.append(STDERR_LINE % error)
00177         return ''.join(msgLines)
00178 

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.result.TestResult._is_relevant_tb_level (   self,
  tb 
) [private]

Definition at line 179 of file result.py.

00179 
00180     def _is_relevant_tb_level(self, tb):
00181         return '__unittest' in tb.tb_frame.f_globals

Here is the caller graph for this function:

Definition at line 83 of file result.py.

00083 
00084     def _restoreStdout(self):
00085         if self.buffer:
00086             if self._mirrorOutput:
00087                 output = sys.stdout.getvalue()
00088                 error = sys.stderr.getvalue()
00089                 if output:
00090                     if not output.endswith('\n'):
00091                         output += '\n'
00092                     self._original_stdout.write(STDOUT_LINE % output)
00093                 if error:
00094                     if not error.endswith('\n'):
00095                         error += '\n'
00096                     self._original_stderr.write(STDERR_LINE % error)
00097 
00098             sys.stdout = self._original_stdout
00099             sys.stderr = self._original_stderr
00100             self._stdout_buffer.seek(0)
00101             self._stdout_buffer.truncate()
00102             self._stderr_buffer.seek(0)
00103             self._stderr_buffer.truncate()

def unittest.result.TestResult._setupStdout (   self) [private]

Definition at line 64 of file result.py.

00064 
00065     def _setupStdout(self):
00066         if self.buffer:
00067             if self._stderr_buffer is None:
00068                 self._stderr_buffer = io.StringIO()
00069                 self._stdout_buffer = io.StringIO()
00070             sys.stdout = self._stdout_buffer
00071             sys.stderr = self._stderr_buffer

def unittest.result.TestResult.addError (   self,
  test,
  err 
)
Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().

Reimplemented in unittest.runner.TextTestResult.

Definition at line 111 of file result.py.

00111 
00112     def addError(self, test, err):
00113         """Called when an error has occurred. 'err' is a tuple of values as
00114         returned by sys.exc_info().
00115         """
00116         self.errors.append((test, self._exc_info_to_string(err, test)))
00117         self._mirrorOutput = True

Here is the call graph for this function:

def unittest.result.TestResult.addExpectedFailure (   self,
  test,
  err 
)
Called when an expected failure/error occured.

Reimplemented in unittest.runner.TextTestResult.

Definition at line 133 of file result.py.

00133 
00134     def addExpectedFailure(self, test, err):
00135         """Called when an expected failure/error occured."""
00136         self.expectedFailures.append(
00137             (test, self._exc_info_to_string(err, test)))

Here is the call graph for this function:

def unittest.result.TestResult.addFailure (   self,
  test,
  err 
)
Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().

Reimplemented in unittest.runner.TextTestResult.

Definition at line 119 of file result.py.

00119 
00120     def addFailure(self, test, err):
00121         """Called when an error has occurred. 'err' is a tuple of values as
00122         returned by sys.exc_info()."""
00123         self.failures.append((test, self._exc_info_to_string(err, test)))
00124         self._mirrorOutput = True

Here is the call graph for this function:

def unittest.result.TestResult.addSkip (   self,
  test,
  reason 
)
Called when a test is skipped.

Reimplemented in unittest.runner.TextTestResult.

Definition at line 129 of file result.py.

00129 
00130     def addSkip(self, test, reason):
00131         """Called when a test is skipped."""
00132         self.skipped.append((test, reason))

def unittest.result.TestResult.addSuccess (   self,
  test 
)

Reimplemented in unittest.runner.TextTestResult.

Definition at line 125 of file result.py.

00125 
00126     def addSuccess(self, test):
00127         "Called when a test has completed successfully"
00128         pass

Called when a test was expected to fail, but succeed.

Reimplemented in unittest.runner.TextTestResult.

Definition at line 139 of file result.py.

00139 
00140     def addUnexpectedSuccess(self, test):
00141         """Called when a test was expected to fail, but succeed."""
00142         self.unexpectedSuccesses.append(test)

Reimplemented in unittest.runner.TextTestResult.

Definition at line 55 of file result.py.

00055 
00056     def printErrors(self):
00057         "Called by TestRunner after test run"

def unittest.result.TestResult.startTest (   self,
  test 
)

Reimplemented in unittest.runner.TextTestResult.

Definition at line 58 of file result.py.

00058 
00059     def startTest(self, test):
00060         "Called when the given test is about to be run"
00061         self.testsRun += 1
00062         self._mirrorOutput = False
00063         self._setupStdout()

Here is the call graph for this function:

Called once before any tests are executed.

See startTest for a method called before each test.

Definition at line 72 of file result.py.

00072 
00073     def startTestRun(self):
00074         """Called once before any tests are executed.
00075 
00076         See startTest for a method called before each test.
00077         """

Definition at line 147 of file result.py.

00147 
00148     def stop(self):
00149         "Indicates that the tests should be aborted"
00150         self.shouldStop = True

def unittest.result.TestResult.stopTest (   self,
  test 
)
Called when the given test has been run

Definition at line 78 of file result.py.

00078 
00079     def stopTest(self, test):
00080         """Called when the given test has been run"""
00081         self._restoreStdout()
00082         self._mirrorOutput = False

Here is the call graph for this function:

Called once after all tests are executed.

See stopTest for a method called after each test.

Definition at line 104 of file result.py.

00104 
00105     def stopTestRun(self):
00106         """Called once after all tests are executed.
00107 
00108         See stopTest for a method called after each test.
00109         """

Definition at line 143 of file result.py.

00143 
00144     def wasSuccessful(self):
00145         "Tells whether or not this result was a success"
00146         return len(self.failures) == len(self.errors) == 0


Member Data Documentation

Definition at line 53 of file result.py.

Definition at line 38 of file result.py.

Definition at line 52 of file result.py.

Definition at line 51 of file result.py.

Definition at line 36 of file result.py.

Definition at line 50 of file result.py.

Definition at line 49 of file result.py.

unittest.result.TestResult._testRunEntered = False [static, private]

Definition at line 37 of file result.py.

Definition at line 48 of file result.py.

Definition at line 42 of file result.py.

Definition at line 45 of file result.py.

Definition at line 40 of file result.py.

Definition at line 41 of file result.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 47 of file result.py.

Definition at line 44 of file result.py.

Definition at line 43 of file result.py.

Definition at line 46 of file result.py.


The documentation for this class was generated from the following file: