Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="testloader-objects.html" /> | |
13 | <link rel="prev" href="testsuite-objects.html" /> | |
14 | <link rel="parent" href="module-unittest.html" /> | |
15 | <link rel="next" href="testloader-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>5.3.7 TestResult Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="5.3.6 TestSuite Objects" | |
25 | href="testsuite-objects.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="5.3 unittest " | |
28 | href="module-unittest.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="5.3.8 TestLoader Objects" | |
31 | href="testloader-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="testsuite-objects.html">5.3.6 TestSuite Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-unittest.html">5.3 unittest </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="testloader-objects.html">5.3.8 TestLoader Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION007370000000000000000"></A><A NAME="testresult-objects"></A> | |
56 | <BR> | |
57 | 5.3.7 TestResult Objects | |
58 | ||
59 | </H2> | |
60 | ||
61 | <P> | |
62 | A <tt class="class">TestResult</tt> object stores the results of a set of tests. The | |
63 | <tt class="class">TestCase</tt> and <tt class="class">TestSuite</tt> classes ensure that results are | |
64 | properly stored; test authors do not need to worry about recording the | |
65 | outcome of tests. | |
66 | ||
67 | <P> | |
68 | Testing frameworks built on top of <tt class="module"><a href="module-unittest.html">unittest</a></tt> may want | |
69 | access to the <tt class="class">TestResult</tt> object generated by running a set of | |
70 | tests for reporting purposes; a <tt class="class">TestResult</tt> instance is | |
71 | returned by the <tt class="method">TestRunner.run()</tt> method for this purpose. | |
72 | ||
73 | <P> | |
74 | Each instance holds the total number of tests run, and collections of | |
75 | failures and errors that occurred among those test runs. The | |
76 | collections contain tuples of <code>(<var>testcase</var>, | |
77 | <var>traceback</var>)</code>, where <var>traceback</var> is a string containing a | |
78 | formatted version of the traceback for the exception. | |
79 | ||
80 | <P> | |
81 | <tt class="class">TestResult</tt> instances have the following attributes that will | |
82 | be of interest when inspecting the results of running a set of tests: | |
83 | ||
84 | <P> | |
85 | <dl><dt><b><tt id='l2h-1161' xml:id='l2h-1161' class="member">errors</tt></b></dt> | |
86 | <dd> | |
87 | A list containing pairs of <tt class="class">TestCase</tt> instances and the | |
88 | formatted tracebacks for tests which raised an exception but did not | |
89 | signal a test failure. | |
90 | ||
91 | <span class="versionnote">Changed in version 2.2: | |
92 | Contains formatted tracebacks instead of | |
93 | <tt class="function">sys.exc_info()</tt> results.</span> | |
94 | ||
95 | </dl> | |
96 | ||
97 | <P> | |
98 | <dl><dt><b><tt id='l2h-1162' xml:id='l2h-1162' class="member">failures</tt></b></dt> | |
99 | <dd> | |
100 | A list containing pairs of <tt class="class">TestCase</tt> instances and the | |
101 | formatted tracebacks for tests which signalled a failure in the code | |
102 | under test. | |
103 | ||
104 | <span class="versionnote">Changed in version 2.2: | |
105 | Contains formatted tracebacks instead of | |
106 | <tt class="function">sys.exc_info()</tt> results.</span> | |
107 | ||
108 | </dl> | |
109 | ||
110 | <P> | |
111 | <dl><dt><b><tt id='l2h-1163' xml:id='l2h-1163' class="member">testsRun</tt></b></dt> | |
112 | <dd> | |
113 | The number of tests which have been started. | |
114 | </dl> | |
115 | ||
116 | <P> | |
117 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
118 | <td><nobr><b><tt id='l2h-1164' xml:id='l2h-1164' class="method">wasSuccessful</tt></b>(</nobr></td> | |
119 | <td><var></var>)</td></tr></table></dt> | |
120 | <dd> | |
121 | Returns true if all tests run so far have passed, otherwise returns | |
122 | false. | |
123 | </dl> | |
124 | ||
125 | <P> | |
126 | The following methods of the <tt class="class">TestResult</tt> class are used to | |
127 | maintain the internal data structures, and may be extended in | |
128 | subclasses to support additional reporting requirements. This is | |
129 | particularly useful in building tools which support interactive | |
130 | reporting while tests are being run. | |
131 | ||
132 | <P> | |
133 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
134 | <td><nobr><b><tt id='l2h-1165' xml:id='l2h-1165' class="method">startTest</tt></b>(</nobr></td> | |
135 | <td><var>test</var>)</td></tr></table></dt> | |
136 | <dd> | |
137 | Called when the test case <var>test</var> is about to be run. | |
138 | </dl> | |
139 | ||
140 | <P> | |
141 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
142 | <td><nobr><b><tt id='l2h-1166' xml:id='l2h-1166' class="method">stopTest</tt></b>(</nobr></td> | |
143 | <td><var>test</var>)</td></tr></table></dt> | |
144 | <dd> | |
145 | Called when the test case <var>test</var> has been executed, regardless | |
146 | of the outcome. | |
147 | </dl> | |
148 | ||
149 | <P> | |
150 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
151 | <td><nobr><b><tt id='l2h-1167' xml:id='l2h-1167' class="method">addError</tt></b>(</nobr></td> | |
152 | <td><var>test, err</var>)</td></tr></table></dt> | |
153 | <dd> | |
154 | Called when the test case <var>test</var> raises an exception without | |
155 | signalling a test failure. <var>err</var> is a tuple of the form | |
156 | returned by <tt class="function">sys.exc_info()</tt>: <code>(<var>type</var>, | |
157 | <var>value</var>, <var>traceback</var>)</code>. | |
158 | </dl> | |
159 | ||
160 | <P> | |
161 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
162 | <td><nobr><b><tt id='l2h-1168' xml:id='l2h-1168' class="method">addFailure</tt></b>(</nobr></td> | |
163 | <td><var>test, err</var>)</td></tr></table></dt> | |
164 | <dd> | |
165 | Called when the test case <var>test</var> signals a failure. | |
166 | <var>err</var> is a tuple of the form returned by | |
167 | <tt class="function">sys.exc_info()</tt>: <code>(<var>type</var>, <var>value</var>, | |
168 | <var>traceback</var>)</code>. | |
169 | </dl> | |
170 | ||
171 | <P> | |
172 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
173 | <td><nobr><b><tt id='l2h-1169' xml:id='l2h-1169' class="method">addSuccess</tt></b>(</nobr></td> | |
174 | <td><var>test</var>)</td></tr></table></dt> | |
175 | <dd> | |
176 | This method is called for a test that does not fail; <var>test</var> is | |
177 | the test case object. | |
178 | </dl> | |
179 | ||
180 | <P> | |
181 | One additional method is available for <tt class="class">TestResult</tt> objects: | |
182 | ||
183 | <P> | |
184 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
185 | <td><nobr><b><tt id='l2h-1170' xml:id='l2h-1170' class="method">stop</tt></b>(</nobr></td> | |
186 | <td><var></var>)</td></tr></table></dt> | |
187 | <dd> | |
188 | This method can be called to signal that the set of tests being run | |
189 | should be aborted. Once this has been called, the | |
190 | <tt class="class">TestRunner</tt> object return to its caller without running any | |
191 | additional tests. This is used by the <tt class="class">TextTestRunner</tt> class | |
192 | to stop the test framework when the user signals an interrupt from | |
193 | the keyboard. Interactive tools which provide runners can use this | |
194 | in a similar manner. | |
195 | </dl> | |
196 | ||
197 | <P> | |
198 | ||
199 | <DIV CLASS="navigation"> | |
200 | <div class='online-navigation'> | |
201 | <p></p><hr /> | |
202 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
203 | <tr> | |
204 | <td class='online-navigation'><a rel="prev" title="5.3.6 TestSuite Objects" | |
205 | href="testsuite-objects.html"><img src='../icons/previous.png' | |
206 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
207 | <td class='online-navigation'><a rel="parent" title="5.3 unittest " | |
208 | href="module-unittest.html"><img src='../icons/up.png' | |
209 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
210 | <td class='online-navigation'><a rel="next" title="5.3.8 TestLoader Objects" | |
211 | href="testloader-objects.html"><img src='../icons/next.png' | |
212 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
213 | <td align="center" width="100%">Python Library Reference</td> | |
214 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
215 | href="contents.html"><img src='../icons/contents.png' | |
216 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
217 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
218 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
219 | <td class='online-navigation'><a rel="index" title="Index" | |
220 | href="genindex.html"><img src='../icons/index.png' | |
221 | border='0' height='32' alt='Index' width='32' /></A></td> | |
222 | </tr></table> | |
223 | <div class='online-navigation'> | |
224 | <b class="navlabel">Previous:</b> | |
225 | <a class="sectref" rel="prev" href="testsuite-objects.html">5.3.6 TestSuite Objects</A> | |
226 | <b class="navlabel">Up:</b> | |
227 | <a class="sectref" rel="parent" href="module-unittest.html">5.3 unittest </A> | |
228 | <b class="navlabel">Next:</b> | |
229 | <a class="sectref" rel="next" href="testloader-objects.html">5.3.8 TestLoader Objects</A> | |
230 | </div> | |
231 | </div> | |
232 | <hr /> | |
233 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
234 | </DIV> | |
235 | <!--End of Navigation Panel--> | |
236 | <ADDRESS> | |
237 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
238 | </ADDRESS> | |
239 | </BODY> | |
240 | </HTML> |