Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / testresult-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="testloader-objects.html" />
<link rel="prev" href="testsuite-objects.html" />
<link rel="parent" href="module-unittest.html" />
<link rel="next" href="testloader-objects.html" />
<meta name='aesop' content='information' />
<title>5.3.7 TestResult Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.3.6 TestSuite Objects"
href="testsuite-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5.3 unittest "
href="module-unittest.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.3.8 TestLoader Objects"
href="testloader-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="testsuite-objects.html">5.3.6 TestSuite Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-unittest.html">5.3 unittest </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="testloader-objects.html">5.3.8 TestLoader Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION007370000000000000000"></A><A NAME="testresult-objects"></A>
<BR>
5.3.7 TestResult Objects
</H2>
<P>
A <tt class="class">TestResult</tt> object stores the results of a set of tests. The
<tt class="class">TestCase</tt> and <tt class="class">TestSuite</tt> classes ensure that results are
properly stored; test authors do not need to worry about recording the
outcome of tests.
<P>
Testing frameworks built on top of <tt class="module"><a href="module-unittest.html">unittest</a></tt> may want
access to the <tt class="class">TestResult</tt> object generated by running a set of
tests for reporting purposes; a <tt class="class">TestResult</tt> instance is
returned by the <tt class="method">TestRunner.run()</tt> method for this purpose.
<P>
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 <code>(<var>testcase</var>,
<var>traceback</var>)</code>, where <var>traceback</var> is a string containing a
formatted version of the traceback for the exception.
<P>
<tt class="class">TestResult</tt> instances have the following attributes that will
be of interest when inspecting the results of running a set of tests:
<P>
<dl><dt><b><tt id='l2h-1161' xml:id='l2h-1161' class="member">errors</tt></b></dt>
<dd>
A list containing pairs of <tt class="class">TestCase</tt> instances and the
formatted tracebacks for tests which raised an exception but did not
signal a test failure.
<span class="versionnote">Changed in version 2.2:
Contains formatted tracebacks instead of
<tt class="function">sys.exc_info()</tt> results.</span>
</dl>
<P>
<dl><dt><b><tt id='l2h-1162' xml:id='l2h-1162' class="member">failures</tt></b></dt>
<dd>
A list containing pairs of <tt class="class">TestCase</tt> instances and the
formatted tracebacks for tests which signalled a failure in the code
under test.
<span class="versionnote">Changed in version 2.2:
Contains formatted tracebacks instead of
<tt class="function">sys.exc_info()</tt> results.</span>
</dl>
<P>
<dl><dt><b><tt id='l2h-1163' xml:id='l2h-1163' class="member">testsRun</tt></b></dt>
<dd>
The number of tests which have been started.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1164' xml:id='l2h-1164' class="method">wasSuccessful</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Returns true if all tests run so far have passed, otherwise returns
false.
</dl>
<P>
The following methods of the <tt class="class">TestResult</tt> 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.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1165' xml:id='l2h-1165' class="method">startTest</tt></b>(</nobr></td>
<td><var>test</var>)</td></tr></table></dt>
<dd>
Called when the test case <var>test</var> is about to be run.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1166' xml:id='l2h-1166' class="method">stopTest</tt></b>(</nobr></td>
<td><var>test</var>)</td></tr></table></dt>
<dd>
Called when the test case <var>test</var> has been executed, regardless
of the outcome.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1167' xml:id='l2h-1167' class="method">addError</tt></b>(</nobr></td>
<td><var>test, err</var>)</td></tr></table></dt>
<dd>
Called when the test case <var>test</var> raises an exception without
signalling a test failure. <var>err</var> is a tuple of the form
returned by <tt class="function">sys.exc_info()</tt>: <code>(<var>type</var>,
<var>value</var>, <var>traceback</var>)</code>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1168' xml:id='l2h-1168' class="method">addFailure</tt></b>(</nobr></td>
<td><var>test, err</var>)</td></tr></table></dt>
<dd>
Called when the test case <var>test</var> signals a failure.
<var>err</var> is a tuple of the form returned by
<tt class="function">sys.exc_info()</tt>: <code>(<var>type</var>, <var>value</var>,
<var>traceback</var>)</code>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1169' xml:id='l2h-1169' class="method">addSuccess</tt></b>(</nobr></td>
<td><var>test</var>)</td></tr></table></dt>
<dd>
This method is called for a test that does not fail; <var>test</var> is
the test case object.
</dl>
<P>
One additional method is available for <tt class="class">TestResult</tt> objects:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1170' xml:id='l2h-1170' class="method">stop</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
This method can be called to signal that the set of tests being run
should be aborted. Once this has been called, the
<tt class="class">TestRunner</tt> object return to its caller without running any
additional tests. This is used by the <tt class="class">TextTestRunner</tt> 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.
</dl>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.3.6 TestSuite Objects"
href="testsuite-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5.3 unittest "
href="module-unittest.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.3.8 TestLoader Objects"
href="testloader-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="testsuite-objects.html">5.3.6 TestSuite Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-unittest.html">5.3 unittest </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="testloader-objects.html">5.3.8 TestLoader Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>