blob: 76477398784055a0ac4905c700be3584c2df19e0 [file] [log] [blame]
Fred Drakeb9ad2282001-04-07 05:41:39 +00001\section{\module{unittest} ---
2 Unit testing framework}
3
4\declaremodule{standard}{unittest}
5\moduleauthor{Steve Purcell}{stephen\textunderscore{}purcell@yahoo.com}
6\sectionauthor{Steve Purcell}{stephen\textunderscore{}purcell@yahoo.com}
7\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
8
9
10The Python unit testing framework, often referred to as ``PyUnit,'' is
11a Python language version of JUnit, by Kent Beck and Erich Gamma.
12JUnit is, in turn, a Java version of Kent's Smalltalk testing
13framework. Each is the de facto standard unit testing framework for
14its respective language.
15
16PyUnit supports test automation, sharing of setup and shutdown code
17for tests, aggregation of tests into collections, and independence of
18the tests from the reporting framework. The \module{unittest} module
19provides classes that make it easy to support these qualities for a
20set of tests.
21
22To achieve this, PyUnit supports three major concepts:
23
24\begin{definitions}
Fred Drake29be7012001-04-10 22:25:06 +000025\term{test fixture}
26A \dfn{test fixture} represents the preparation needed to perform one
27or more tests, and any associate cleanup actions. This may involve,
28for example, creating temporary or proxy databases, directories, or
29starting a server process.
30
Fred Drakeb9ad2282001-04-07 05:41:39 +000031\term{test case}
32A \dfn{test case} is the smallest unit of testing. It checks for a
33specific response to a particular set of inputs. PyUnit provides a
34base class, \class{TestCase}, which may be used to create new test
35cases.
36
37\term{test suite}
38A \dfn{test suite} is a collection of test cases, test suites, or
39both. It is used to aggregate tests that should be executed
40together.
41
42\term{test runner}
43A \dfn{test runner} is a component which orchestrates the execution of
44tests and provides the outcome to the user. The runner may use a
45graphical interface, a textual interface, or return a special value to
46indicate the results of executing the tests.
47\end{definitions}
48
49
50
51\begin{seealso}
52 \seetitle[http://pyunit.sourceforge.net/]{PyUnit Web Site}{The
53 source for further information on PyUnit.}
54 \seetitle[http://www.XProgramming.com/testfram.htm]{Simple Smalltalk
55 Testing: With Patterns}{Kent Beck's original paper on
56 testing frameworks using the pattern shared by
57 \module{unittest}.}
58\end{seealso}
59
60
61\subsection{Mapping concepts to classes
62 \label{test-concept-classes}}
63
64
65\subsection{Organizing test code
66 \label{organizing-tests}}
67
Fred Drake0056a422001-04-12 04:50:06 +000068The basic building blocks of unit testing are \dfn{test cases} ---
69single scenarios that must be set up and checked for correctness. In
70PyUnit, test cases are represented by instances of the
71\class{TestCase} class in the \refmodule{unittest} module. To make
72your own test cases you must write subclasses of \class{TestCase}, or
73use \class{FunctionTestCase}.
74
75An instance of a \class{TestCase}-derived class is an object that can
76completely run a single test method, together with optional set-up
77and tidy-up code.
78
79The testing code of a \class{TestCase} instance should be entirely
80self contained, such that it can be run either in isolation or in
81arbitrary combination with any number of other test cases.
82
83The simplest test case subclass will simply override the
84\method{runTest()} method in order to perform specific testing code:
85
86\begin{verbatim}
87import unittest
88
89class DefaultWidgetSizeTestCase(unittest.TestCase):
90 def runTest(self):
91 widget = Widget("The widget")
92 assert widget.size() == (50,50), 'incorrect default size'
93\end{verbatim}
94
95Note that in order to test something, we just use the built-in 'assert'
96statement of Python. If the test fails when the test case runs,
97\class{TestFailed} will be raised, and the testing framework
98will identify the test case as a \dfn{failure}. Other exceptions that
99do not arise from explicit 'assert' checks are identified by the testing
100framework as dfn{errors}.
101
102The way to run a test case will be described later. For now, note
103that to construct an instance of such a test case, we call its
104constructor without arguments:
105
106\begin{verbatim}
107testCase = DefaultWidgetSizeTestCase()
108\end{verbatim}
109
110Now, such test cases can be numerous, and their set-up can be
111repetitive. In the above case, constructing a ``Widget'' in each of
112100 Widget test case subclasses would mean unsightly duplication.
113
114Luckily, we can factor out such set-up code by implementing a method
115called \method{setUp()}, which the testing framework will
116automatically call for us when we run the test:
117
118\begin{verbatim}
119import unittest
120
121class SimpleWidgetTestCase(unittest.TestCase):
122 def setUp(self):
123 self.widget = Widget("The widget")
124
125class DefaultWidgetSizeTestCase(SimpleWidgetTestCase):
126 def runTest(self):
127 assert self.widget.size() == (50,50), 'incorrect default size'
128
129class WidgetResizeTestCase(SimpleWidgetTestCase):
130 def runTest(self):
131 self.widget.resize(100,150)
132 assert self.widget.size() == (100,150), \
133 'wrong size after resize'
134\end{verbatim}
135
136If the \method{setUp()} method raises an exception while the test is
137running, the framework will consider the test to have suffered an
138error, and the \method{runTest()} method will not be executed.
139
140Similarly, we can provide a \method{tearDown()} method that tidies up
141after the \method{runTest()} method has been run:
142
143\begin{verbatim}
144import unittest
145
146class SimpleWidgetTestCase(unittest.TestCase):
147 def setUp(self):
148 self.widget = Widget("The widget")
149
150 def tearDown(self):
151 self.widget.dispose()
152 self.widget = None
153\end{verbatim}
154
155If \method{setUp()} succeeded, the \method{tearDown()} method will be
156run regardless of whether or not \method{runTest()} succeeded.
157
158Such a working environment for the testing code is called a
159\dfn{fixture}.
160
161Often, many small test cases will use the same fixture. In this case,
162we would end up subclassing \class{SimpleWidgetTestCase} into many
163small one-method classes such as
164\class{DefaultWidgetSizeTestCase}. This is time-consuming and
165discouraging, so in the same vein as JUnit, PyUnit provides a simpler
166mechanism:
167
168\begin{verbatim}
169import unittest
170
171class WidgetTestCase(unittest.TestCase):
172 def setUp(self):
173 self.widget = Widget("The widget")
174
175 def tearDown(self):
176 self.widget.dispose()
177 self.widget = None
178
179 def testDefaultSize(self):
180 assert self.widget.size() == (50,50), \
181 'incorrect default size'
182
183 def testResize(self):
184 self.widget.resize(100,150)
185 assert self.widget.size() == (100,150), \
186 'wrong size after resize'
187\end{verbatim}
188
189Here we have not provided a \method{runTest()} method, but have
190instead provided two different test methods. Class instances will now
191each run one of the \method{test*()} methods, with \code{self.widget}
192created and destroyed separately for each instance. When creating an
193instance we must specify the test method it is to run. We do this by
194passing the method name in the constructor:
195
196\begin{verbatim}
197defaultSizeTestCase = WidgetTestCase("testDefaultSize")
198resizeTestCase = WidgetTestCase("testResize")
199\end{verbatim}
200
201Test case instances are grouped together according to the features
202they test. PyUnit provides a mechanism for this: the \class{test
203suite}, represented by the class \class{TestSuite} in the
204\refmodule{unittest} module:
205
206\begin{verbatim}
207widgetTestSuite = unittest.TestSuite()
208widgetTestSuite.addTest(WidgetTestCase("testDefaultSize"))
209widgetTestSuite.addTest(WidgetTestCase("testResize"))
210\end{verbatim}
211
212For the ease of running tests, as we will see later, it is a good
213idea to provide in each test module a callable object that returns a
214pre-built test suite:
215
216\begin{verbatim}
217def suite():
218 suite = unittest.TestSuite()
219 suite.addTest(WidgetTestCase("testDefaultSize"))
220 suite.addTest(WidgetTestCase("testResize"))
221 return suite
222\end{verbatim}
223
224or even:
225
226\begin{verbatim}
227class WidgetTestSuite(unittest.TestSuite):
228 def __init__(self):
229 unittest.TestSuite.__init__(self,map(WidgetTestCase,
230 ("testDefaultSize",
231 "testResize")))
232\end{verbatim}
233
234(The latter is admittedly not for the faint-hearted!)
235
236Since it is a common pattern to create a \class{TestCase} subclass
237with many similarly named test functions, there is a convenience
238function called \function{makeSuite()} provided in the
239\refmodule{unittest} module that constructs a test suite that
240comprises all of the test cases in a test case class:
241
242\begin{verbatim}
243suite = unittest.makeSuite(WidgetTestCase,'test')
244\end{verbatim}
245
246Note that when using the \function{makeSuite()} function, the order in
247which the various test cases will be run by the test suite is the
248order determined by sorting the test function names using the
249\function{cmp()} built-in function.
250
251Often it is desirable to group suites of test cases together, so as to
252run tests for the whole system at once. This is easy, since
253\class{TestSuite} instances can be added to a \class{TestSuite} just
254as \class{TestCase} instances can be added to a \class{TestSuite}:
255
256\begin{verbatim}
257suite1 = module1.TheTestSuite()
258suite2 = module2.TheTestSuite()
259alltests = unittest.TestSuite((suite1, suite2))
260\end{verbatim}
261
262You can place the definitions of test cases and test suites in the
263same modules as the code they are to test (e.g.\ \file{widget.py}),
264but there are several advantages to placing the test code in a
265separate module, such as \file{widgettests.py}:
266
267\begin{itemize}
268 \item The test module can be run standalone from the command line.
269 \item The test code can more easily be separated from shipped code.
270 \item There is less temptation to change test code to fit the code.
271 it tests without a good reason.
272 \item Test code should be modified much less frequently than the
273 code it tests.
274 \item Tested code can be refactored more easily.
275 \item Tests for modules written in C must be in separate modules
276 anyway, so why not be consistent?
277 \item If the testing strategy changes, there is no need to change
278 the source code.
279\end{itemize}
280
Fred Drakeb9ad2282001-04-07 05:41:39 +0000281
282\subsection{Re-using old test code
283 \label{legacy-unit-tests}}
284
285Some users will find that they have existing test code that they would
286like to run from PyUnit, without converting every old test function to
287a \class{TestCase} subclass.
288
289For this reason, PyUnit provides a \class{FunctionTestCase} class.
290This subclass of \class{TestCase} can be used to wrap an existing test
291function. Set-up and tear-down functions can also optionally be
292wrapped.
293
294Given the following test function:
295
296\begin{verbatim}
297def testSomething():
298 something = makeSomething()
299 assert something.name is not None
300 # ...
301\end{verbatim}
302
303one can create an equivalent test case instance as follows:
304
305\begin{verbatim}
306testcase = unittest.FunctionTestCase(testSomething)
307\end{verbatim}
308
309If there are additional set-up and tear-down methods that should be
310called as part of the test case's operation, they can also be provided:
311
312\begin{verbatim}
313testcase = unittest.FunctionTestCase(testSomething,
314 setUp=makeSomethingDB,
315 tearDown=deleteSomethingDB)
316\end{verbatim}
317
318
Fred Drake0056a422001-04-12 04:50:06 +0000319\strong{Note:} PyUnit supports the use of \exception{AssertionError}
320as an indicator of test failure, but does not recommend it. Future
321versions may treat \exception{AssertionError} differently.
322
323
Fred Drakeb9ad2282001-04-07 05:41:39 +0000324\subsection{Classes and functions
325 \label{unittest-contents}}
326
327\begin{classdesc}{TestCase}{}
328 Instances of the \class{TestCase} class represent the smallest
329 testable units in a set of tests. This class is intended to be used
330 as a base class, with specific tests being implemented by concrete
331 subclasses. This class implements the interface needed by the test
332 runner to allow it to drive the test, and methods that the test code
333 can use to check for and report various kinds of failures.
334\end{classdesc}
335
336\begin{classdesc}{FunctionTestCase}{testFunc\optional{,
337 setup\optional{, tearDown\optional{, description}}}}
338 This class implements the portion of the \class{TestCase} interface
339 which allows the test runner to drive the test, but does not provide
340 the methods which test code can use to check and report errors.
341 This is used to create test cases using legacy test code, allowing
342 it to be integrated into a \refmodule{unittest}-based test
343 framework.
344\end{classdesc}
345
Fred Drake29be7012001-04-10 22:25:06 +0000346\begin{classdesc}{TestSuite}{\optional{tests}}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000347 This class represents an aggregation of individual tests cases and
348 test suites. The class presents the interface needed by the test
349 runner to allow it to be run as any other test case, but all the
350 contained tests and test suites are executed. Additional methods
Fred Drake29be7012001-04-10 22:25:06 +0000351 are provided to add test cases and suites to the aggregation. If
352 \var{tests} is given, it must be a sequence of individual tests that
353 will be added to the suite.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000354\end{classdesc}
355
356\begin{classdesc}{TestLoader}{}
Fred Drake29be7012001-04-10 22:25:06 +0000357 This class is responsible for loading tests according to various
358 criteria and returning them wrapped in a \class{TestSuite}.
359 It can load all tests within a given module or \class{TestCase}
360 class. When loading from a module, it considers all
361 \class{TestCase}-derived classes. For each such class, it creates
362 an instance for each method with a name beginning with the string
363 \samp{test}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000364\end{classdesc}
365
366\begin{classdesc}{TextTestRunner}{\optional{stream\optional{,
367 descriptions\optional{, verbosity}}}}
Fred Drake29be7012001-04-10 22:25:06 +0000368 A basic test runner implementation which prints results on standard
369 output. It has a few configurable parameters, but is essentially
370 very simple. Graphical applications which run test suites should
371 provide alternate implementations.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000372\end{classdesc}
373
374\begin{funcdesc}{main}{\optional{module\optional{,
375 defaultTest\optional{, argv\optional{,
376 testRunner\optional{, testRunner}}}}}}
Fred Drake0056a422001-04-12 04:50:06 +0000377 A command-line program that runs a set of tests; this is primarily
378 for making test modules conveniently executable. The simplest use
379 for this function is:
Fred Drakeb9ad2282001-04-07 05:41:39 +0000380
381\begin{verbatim}
382if __name__ == '__main__':
383 unittest.main()
384\end{verbatim}
385\end{funcdesc}
386
Fred Drake0056a422001-04-12 04:50:06 +0000387\begin{excdesc}{TestFailed}
388 Exception raised to indicate that a test failed. The
389 \method{TestCase.fail()} method is responsible for creating and
390 raising this exception.
391\end{excdesc}
392
Fred Drakeb9ad2282001-04-07 05:41:39 +0000393
394\subsection{TestCase Objects
395 \label{testcase-objects}}
396
Fred Drake29be7012001-04-10 22:25:06 +0000397Each \class{TestCase} instance represents a single test, but each
398concrete subclass may be used to define multiple tests --- the
399concrete class represents a single test fixture. The fixture is
400created and cleaned up for each test case.
401
402\class{TestCase} instances provide three groups of methods: one group
403used to run the test, another used by the test implementation to
404check conditions and report failures, and some inquiry methods
405allowing information about the test itself to be gathered.
406
407Methods in the first group are:
408
409\begin{methoddesc}[TestCase]{setUp}{}
410 Method called to prepare the test fixture. This is called
411 immediately before calling the test method; any exception raised by
412 this method will be considered an error rather than a test failure.
413 The default implementation does nothing.
414\end{methoddesc}
415
416\begin{methoddesc}[TestCase]{run}{\optional{result}}
417 Run the test, collecting the result into the test result object
418 passed as \var{result}. If \var{result} is omitted or \code{None},
419 a temporary result object is created and used, but is not made
420 available to the caller. This is equivalent to simply calling the
421 \class{TestCase} instance.
422\end{methoddesc}
423
424\begin{methoddesc}[TestCase]{tearDown}{}
425 Method called immediately after the test method has been called and
426 the result recorded. This is called even if the test method raised
427 an exception, so the implementation in subclasses may need to be
428 particularly careful about checking internal state. Any exception
429 raised by this method will be considered an error rather than a test
430 failure. The default implementation does nothing.
431\end{methoddesc}
432
433\begin{methoddesc}[TestCase]{debug}{}
434 Run the test without collecting the result. This allows exceptions
435 raised by the test to be propogated to the caller, and can be used
436 to support running tests under a debugger.
437\end{methoddesc}
438
439
Fred Drake0056a422001-04-12 04:50:06 +0000440The test code can use any of the following methods to check for and
441report failures:
Fred Drake29be7012001-04-10 22:25:06 +0000442
443\begin{methoddesc}[TestCase]{failUnless}{expr\optional{, msg}}
Fred Drake29be7012001-04-10 22:25:06 +0000444 This method is similar to the \keyword{assert} statement, except it
445 works even when Python is executed in ``optimizing'' mode (using the
Fred Drake0056a422001-04-12 04:50:06 +0000446 \programopt{-O} command line switch), and raises the
447 \exception{TestFailed} exception. If \var{expr} is false,
448 \exception{TestFailed} will be raised with \var{msg} as the
Fred Drake29be7012001-04-10 22:25:06 +0000449 message describing the failure; \code{None} will be used for the
Fred Drake0056a422001-04-12 04:50:06 +0000450 message if \var{msg} is omitted.
Fred Drake29be7012001-04-10 22:25:06 +0000451\end{methoddesc}
452
Fred Drake0056a422001-04-12 04:50:06 +0000453\begin{methoddesc}[TestCase]{failUnlessEqual}{first, second\optional{, msg}}
Fred Drake29be7012001-04-10 22:25:06 +0000454 Test that \var{first} and \var{second} are equal. If the values do
455 not compare equal, the test will fail with the explanation given by
Fred Drake0056a422001-04-12 04:50:06 +0000456 \var{msg}, or \code{None}. Note that using \method{failUnlessEqual()}
Fred Drake29be7012001-04-10 22:25:06 +0000457 improves upon doing the comparison as the first parameter to
458 \method{failUnless()} is that the default value for \var{msg} can be
459 computed to include representations of both \var{first} and
460 \var{second}.
461\end{methoddesc}
462
Fred Drake0056a422001-04-12 04:50:06 +0000463\begin{methoddesc}[TestCase]{failIfEqual}{first, second\optional{, msg}}
Fred Drake29be7012001-04-10 22:25:06 +0000464 Test that \var{first} and \var{second} are not equal. If the values
465 do compare equal, the test will fail with the explanation given by
Fred Drake0056a422001-04-12 04:50:06 +0000466 \var{msg}, or \code{None}. Note that using \method{failIfEqual()}
Fred Drake29be7012001-04-10 22:25:06 +0000467 improves upon doing the comparison as the first parameter to
468 \method{failUnless()} is that the default value for \var{msg} can be
469 computed to include representations of both \var{first} and
470 \var{second}.
471\end{methoddesc}
472
473\begin{methoddesc}[TestCase]{failIf}{expr\optional{, msg}}
Fred Drake0056a422001-04-12 04:50:06 +0000474 The inverse of the \method{failUnless()} method is the
475 \method{failIf()} method. This raises \exception{TestFailed} if
Fred Drake29be7012001-04-10 22:25:06 +0000476 \var{expr} is true, with \var{msg} or \code{None} for the error
477 message.
478\end{methoddesc}
479
480\begin{methoddesc}[TestCase]{fail}{\optional{msg}}
481 Fail unconditionally, with \var{msg} or \code{None} for the error
482 message.
483\end{methoddesc}
484
485
486Testing frameworks can use the following methods to collect
487information on the test:
488
489\begin{methoddesc}[TestCase]{countTestCases}{}
490 Return the number of tests represented by the this test object. For
491 \class{TestCase} instances, this will always be \code{1}, but this
492 method is also implemented by the \class{TestSuite} class, which can
493 return larger values.
494\end{methoddesc}
495
496\begin{methoddesc}[TestCase]{defaultTestResult}{}
497 Return the default type of test result object to be used to run this
498 test.
499\end{methoddesc}
500
501\begin{methoddesc}[TestCase]{id}{}
502 Return a string identifying the specific test case. This is usually
503 the full name of the test method, including the module and class
504 names.
505\end{methoddesc}
506
507\begin{methoddesc}[TestCase]{shortDescription}{}
508 Returns a one-line description of the test, or \code{None} if no
509 description has been provided. The default implementation of this
510 method returns the first line of the test method's docstring, if
511 available, or \code{None}.
512\end{methoddesc}
513
Fred Drakeb9ad2282001-04-07 05:41:39 +0000514
515\subsection{TestSuite Objects
516 \label{testsuite-objects}}
517
518\class{TestSuite} objects behave much like \class{TestCase} objects,
519except they do not actually implement a test. Instead, they are used
520to aggregate tests into groups that should be run together. Some
521additional methods are available to add tests to \class{TestSuite}
522instances:
523
524\begin{methoddesc}[TestSuite]{addTest}{test}
525 Add a \class{TestCase} or \class{TestSuite} to the set of tests that
526 make up the suite.
527\end{methoddesc}
528
529\begin{methoddesc}[TestSuite]{addTests}{tests}
530 Add all the tests from a sequence of \class{TestCase} and
531 \class{TestSuite} instances to this test suite.
532\end{methoddesc}
533
534
535\subsection{TestResult Objects
536 \label{testresult-objects}}
537
538A \class{TestResult} object stores the results of a set of tests. The
539\class{TestCase} and \class{TestSuite} classes ensure that results are
540properly stored; test authors do not need to worry about recording the
541outcome of tests.
542
543Testing frameworks built on top of \refmodule{unittest} may want
544access to the \class{TestResult} object generated by running a set of
545tests for reporting purposes; a \class{TestResult} instance is
546returned by the \method{TestRunner.run()} method for this purpose.
547
548Each instance holds the total number of tests run, and collections of
549failures and errors that occurred among those test runs. The
550collections contain tuples of \code{(\var{testcase},
551\var{exceptioninfo})}, where \var{exceptioninfo} is a tuple as
552returned by \function{sys.exc_info()}.
553
554\class{TestResult} instances have the following attributes that will
555be of interest when inspecting the results of running a set of tests:
556
557\begin{memberdesc}[TestResult]{errors}
558 A list containing pairs of \class{TestCase} instances and the
559 \function{sys.exc_info()} results for tests which raised exceptions
Fred Drake0056a422001-04-12 04:50:06 +0000560 other than \exception{AssertionError} and \exception{TestFailed}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000561\end{memberdesc}
562
563\begin{memberdesc}[TestResult]{failures}
564 A list containing pairs of \class{TestCase} instances and the
Fred Drake0056a422001-04-12 04:50:06 +0000565 \function{sys.exc_info()} results for tests which raised either
566 \exception{TestFailed} or \exception{AssertionError}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000567\end{memberdesc}
568
569\begin{memberdesc}[TestResult]{testsRun}
570 The number of tests which have been started.
571\end{memberdesc}
572
573\begin{methoddesc}[TestResult]{wasSuccessful}{}
574 Returns true if all tests run so far have passed, otherwise returns
575 false.
576\end{methoddesc}
577
578
579The following methods of the \class{TestResult} class are used to
580maintain the internal data structures, and mmay be extended in
581subclasses to support additional reporting requirements. This is
582particularly useful in building GUI tools which support interactive
583reporting while tests are being run.
584
585\begin{methoddesc}[TestResult]{startTest}{test}
586 Called when the test case \var{test} is about to be run.
587\end{methoddesc}
588
589\begin{methoddesc}[TestResult]{stopTest}{test}
590 Called when the test case \var{test} has been executed, regardless
591 of the outcome.
592\end{methoddesc}
593
594\begin{methoddesc}[TestResult]{addError}{test, err}
595 Called when the test case \var{test} results in an exception other
Fred Drake0056a422001-04-12 04:50:06 +0000596 than \exception{TestFailed} or \exception{AssertionError}.
597 \var{err} is a tuple of the form returned by
598 \function{sys.exc_info()}: \code{(\var{type}, \var{value},
599 \var{traceback})}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000600\end{methoddesc}
601
602\begin{methoddesc}[TestResult]{addFailure}{test, err}
603 Called when the test case \var{test} results in an
604 \exception{AssertionError} exception; the assumption is that the
Fred Drake0056a422001-04-12 04:50:06 +0000605 test raised either \exception{TestFailed} or
606 \exception{AssertionError} and not the implementation being tested.
607 \var{err} is a tuple of the form returned by
608 \function{sys.exc_info()}: \code{(\var{type}, \var{value},
609 \var{traceback})}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000610\end{methoddesc}
611
612\begin{methoddesc}[TestResult]{addSuccess}{test}
613 This method is called for a test that does not fail; \var{test} is
614 the test case object.
615\end{methoddesc}
616
617
618One additional method is available for \class{TestResult} objects:
619
620\begin{methoddesc}[TestResult]{stop}{}
621 This method can be called to signal that the set of tests being run
622 should be aborted. Once this has been called, the
623 \class{TestRunner} object return to its caller without running any
624 additional tests. This is used by the \class{TextTestRunner} class
625 to stop the test framework when the user signals an interrupt from
626 the keyboard. GUI tools which provide runners can use this in a
627 similar manner.
628\end{methoddesc}