blob: f40493d35baa999690bd1f91c4f7692e121335aa [file] [log] [blame]
Fred Drakeb9ad2282001-04-07 05:41:39 +00001\section{\module{unittest} ---
2 Unit testing framework}
3
4\declaremodule{standard}{unittest}
Fred Drake62a26692001-04-12 19:34:38 +00005\modulesynopsis{Unit testing framework for Python.}
Fred Drakeb9ad2282001-04-07 05:41:39 +00006\moduleauthor{Steve Purcell}{stephen\textunderscore{}purcell@yahoo.com}
7\sectionauthor{Steve Purcell}{stephen\textunderscore{}purcell@yahoo.com}
8\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
Raymond Hettinger9de3c212003-07-10 22:14:41 +00009\sectionauthor{Raymond Hettinger}{python@rcn.com}
Fred Drakeb9ad2282001-04-07 05:41:39 +000010
Fred Drake5430f4e2002-10-10 16:16:25 +000011\versionadded{2.1}
Fred Drakeb9ad2282001-04-07 05:41:39 +000012
Thomas Wouters0e3f5912006-08-11 14:57:12 +000013The Python unit testing framework, sometimes referred to as ``PyUnit,'' is
Fred Drakeb9ad2282001-04-07 05:41:39 +000014a Python language version of JUnit, by Kent Beck and Erich Gamma.
15JUnit is, in turn, a Java version of Kent's Smalltalk testing
16framework. Each is the de facto standard unit testing framework for
17its respective language.
18
Thomas Wouters0e3f5912006-08-11 14:57:12 +000019\module{unittest} supports test automation, sharing of setup and shutdown
20code for tests, aggregation of tests into collections, and independence of
Fred Drakeb9ad2282001-04-07 05:41:39 +000021the tests from the reporting framework. The \module{unittest} module
22provides classes that make it easy to support these qualities for a
23set of tests.
24
Thomas Wouters0e3f5912006-08-11 14:57:12 +000025To achieve this, \module{unittest} supports some important concepts:
Fred Drakeb9ad2282001-04-07 05:41:39 +000026
27\begin{definitions}
Fred Drake29be7012001-04-10 22:25:06 +000028\term{test fixture}
29A \dfn{test fixture} represents the preparation needed to perform one
30or more tests, and any associate cleanup actions. This may involve,
31for example, creating temporary or proxy databases, directories, or
32starting a server process.
33
Fred Drakeb9ad2282001-04-07 05:41:39 +000034\term{test case}
35A \dfn{test case} is the smallest unit of testing. It checks for a
Thomas Wouters0e3f5912006-08-11 14:57:12 +000036specific response to a particular set of inputs. \module{unittest}
37provides a base class, \class{TestCase}, which may be used to create
38new test cases.
Fred Drakeb9ad2282001-04-07 05:41:39 +000039
40\term{test suite}
41A \dfn{test suite} is a collection of test cases, test suites, or
42both. It is used to aggregate tests that should be executed
43together.
44
45\term{test runner}
46A \dfn{test runner} is a component which orchestrates the execution of
47tests and provides the outcome to the user. The runner may use a
48graphical interface, a textual interface, or return a special value to
49indicate the results of executing the tests.
50\end{definitions}
51
52
Fred Drake62a26692001-04-12 19:34:38 +000053The test case and test fixture concepts are supported through the
54\class{TestCase} and \class{FunctionTestCase} classes; the former
Just van Rossumedd179e2002-12-15 13:14:22 +000055should be used when creating new tests, and the latter can be used when
Thomas Wouters0e3f5912006-08-11 14:57:12 +000056integrating existing test code with a \module{unittest}-driven framework.
57When building test fixtures using \class{TestCase}, the \method{setUp()}
Fred Drake62a26692001-04-12 19:34:38 +000058and \method{tearDown()} methods can be overridden to provide
59initialization and cleanup for the fixture. With
60\class{FunctionTestCase}, existing functions can be passed to the
61constructor for these purposes. When the test is run, the
62fixture initialization is run first; if it succeeds, the cleanup
63method is run after the test has been executed, regardless of the
64outcome of the test. Each instance of the \class{TestCase} will only
65be used to run a single test method, so a new fixture is created for
66each test.
67
68Test suites are implemented by the \class{TestSuite} class. This
69class allows individual tests and test suites to be aggregated; when
70the suite is executed, all tests added directly to the suite and in
71``child'' test suites are run.
72
73A test runner is an object that provides a single method,
74\method{run()}, which accepts a \class{TestCase} or \class{TestSuite}
75object as a parameter, and returns a result object. The class
Thomas Wouters0e3f5912006-08-11 14:57:12 +000076\class{TestResult} is provided for use as the result object.
77\module{unittest} provides the \class{TextTestRunner} as an example
78test runner which reports test results on the standard error stream by
79default. Alternate runners can be implemented for other environments
80(such as graphical environments) without any need to derive from a
81specific class.
Fred Drake62a26692001-04-12 19:34:38 +000082
Fred Drakeb9ad2282001-04-07 05:41:39 +000083
84\begin{seealso}
Fred Drakeae55d5f2003-12-31 04:34:50 +000085 \seemodule{doctest}{Another test-support module with a very
86 different flavor.}
Fred Drakeb9ad2282001-04-07 05:41:39 +000087 \seetitle[http://www.XProgramming.com/testfram.htm]{Simple Smalltalk
88 Testing: With Patterns}{Kent Beck's original paper on
89 testing frameworks using the pattern shared by
90 \module{unittest}.}
91\end{seealso}
92
93
Raymond Hettingerd21fd7b2003-09-16 22:04:31 +000094\subsection{Basic example \label{minimal-example}}
Raymond Hettinger9de3c212003-07-10 22:14:41 +000095
96The \module{unittest} module provides a rich set of tools for
97constructing and running tests. This section demonstrates that a
98small subset of the tools suffice to meet the needs of most users.
99
100Here is a short script to test three functions from the
101\refmodule{random} module:
102
103\begin{verbatim}
104import random
105import unittest
106
107class TestSequenceFunctions(unittest.TestCase):
108
109 def setUp(self):
110 self.seq = range(10)
111
112 def testshuffle(self):
113 # make sure the shuffled sequence does not lose any elements
114 random.shuffle(self.seq)
115 self.seq.sort()
116 self.assertEqual(self.seq, range(10))
117
118 def testchoice(self):
119 element = random.choice(self.seq)
120 self.assert_(element in self.seq)
121
122 def testsample(self):
123 self.assertRaises(ValueError, random.sample, self.seq, 20)
124 for element in random.sample(self.seq, 5):
125 self.assert_(element in self.seq)
126
127if __name__ == '__main__':
128 unittest.main()
129\end{verbatim}
130
Fred Drakeae55d5f2003-12-31 04:34:50 +0000131A testcase is created by subclassing \class{unittest.TestCase}.
Raymond Hettinger9de3c212003-07-10 22:14:41 +0000132The three individual tests are defined with methods whose names start with
Fred Drakeae55d5f2003-12-31 04:34:50 +0000133the letters \samp{test}. This naming convention informs the test runner
Raymond Hettinger9de3c212003-07-10 22:14:41 +0000134about which methods represent tests.
135
136The crux of each test is a call to \method{assertEqual()} to
137check for an expected result; \method{assert_()} to verify a condition;
138or \method{assertRaises()} to verify that an expected exception gets
139raised. These methods are used instead of the \keyword{assert} statement
140so the test runner can accumulate all test results and produce a report.
141
142When a \method{setUp()} method is defined, the test runner will run that
143method prior to each test. Likewise, if a \method{tearDown()} method is
144defined, the test runner will invoke that method after each test. In the
145example, \method{setUp()} was used to create a fresh sequence for each test.
146
Fred Drakeae55d5f2003-12-31 04:34:50 +0000147The final block shows a simple way to run the tests.
148\function{unittest.main()} provides a command line interface to the
149test script. When run from the command line, the above script
150produces an output that looks like this:
Raymond Hettinger9de3c212003-07-10 22:14:41 +0000151
152\begin{verbatim}
153...
154----------------------------------------------------------------------
155Ran 3 tests in 0.000s
156
157OK
158\end{verbatim}
159
Fred Drakeae55d5f2003-12-31 04:34:50 +0000160Instead of \function{unittest.main()}, there are other ways to run the tests
Raymond Hettinger9de3c212003-07-10 22:14:41 +0000161with a finer level of control, less terse output, and no requirement to be
162run from the command line. For example, the last two lines may be replaced
163with:
164
165\begin{verbatim}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000166suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
Raymond Hettinger9de3c212003-07-10 22:14:41 +0000167unittest.TextTestRunner(verbosity=2).run(suite)
168\end{verbatim}
169
170Running the revised script from the interpreter or another script
171produces the following output:
172
173\begin{verbatim}
174testchoice (__main__.TestSequenceFunctions) ... ok
175testsample (__main__.TestSequenceFunctions) ... ok
176testshuffle (__main__.TestSequenceFunctions) ... ok
177
178----------------------------------------------------------------------
179Ran 3 tests in 0.110s
180
181OK
182\end{verbatim}
183
184The above examples show the most commonly used \module{unittest} features
185which are sufficient to meet many everyday testing needs. The remainder
186of the documentation explores the full feature set from first principles.
187
188
Fred Drakeb9ad2282001-04-07 05:41:39 +0000189\subsection{Organizing test code
190 \label{organizing-tests}}
191
Fred Drake0056a422001-04-12 04:50:06 +0000192The basic building blocks of unit testing are \dfn{test cases} ---
193single scenarios that must be set up and checked for correctness. In
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000194\module{unittest}, test cases are represented by instances of
195\module{unittest}'s \class{TestCase} class. To make
Fred Drake0056a422001-04-12 04:50:06 +0000196your own test cases you must write subclasses of \class{TestCase}, or
197use \class{FunctionTestCase}.
198
199An instance of a \class{TestCase}-derived class is an object that can
200completely run a single test method, together with optional set-up
201and tidy-up code.
202
203The testing code of a \class{TestCase} instance should be entirely
204self contained, such that it can be run either in isolation or in
205arbitrary combination with any number of other test cases.
206
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000207The simplest \class{TestCase} subclass will simply override the
Fred Drake0056a422001-04-12 04:50:06 +0000208\method{runTest()} method in order to perform specific testing code:
209
210\begin{verbatim}
211import unittest
212
213class DefaultWidgetSizeTestCase(unittest.TestCase):
214 def runTest(self):
215 widget = Widget("The widget")
Fred Drake62a26692001-04-12 19:34:38 +0000216 self.failUnless(widget.size() == (50,50), 'incorrect default size')
Fred Drake0056a422001-04-12 04:50:06 +0000217\end{verbatim}
218
Fred Drake62a26692001-04-12 19:34:38 +0000219Note that in order to test something, we use the one of the
220\method{assert*()} or \method{fail*()} methods provided by the
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000221\class{TestCase} base class. If the test fails, an exception will be
222raised, and \module{unittest} will identify the test case as a
223\dfn{failure}. Any other exceptions will be treated as \dfn{errors}.
224This helps you identify where the problem is: \dfn{failures} are caused by
225incorrect results - a 5 where you expected a 6. \dfn{Errors} are caused by
226incorrect code - e.g., a \exception{TypeError} caused by an incorrect
227function call.
Fred Drake0056a422001-04-12 04:50:06 +0000228
229The way to run a test case will be described later. For now, note
230that to construct an instance of such a test case, we call its
231constructor without arguments:
232
233\begin{verbatim}
234testCase = DefaultWidgetSizeTestCase()
235\end{verbatim}
236
237Now, such test cases can be numerous, and their set-up can be
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000238repetitive. In the above case, constructing a \class{Widget} in each of
Fred Drake0056a422001-04-12 04:50:06 +0000239100 Widget test case subclasses would mean unsightly duplication.
240
241Luckily, we can factor out such set-up code by implementing a method
242called \method{setUp()}, which the testing framework will
243automatically call for us when we run the test:
244
245\begin{verbatim}
246import unittest
247
248class SimpleWidgetTestCase(unittest.TestCase):
249 def setUp(self):
250 self.widget = Widget("The widget")
251
252class DefaultWidgetSizeTestCase(SimpleWidgetTestCase):
253 def runTest(self):
Fred Drake62a26692001-04-12 19:34:38 +0000254 self.failUnless(self.widget.size() == (50,50),
255 'incorrect default size')
Fred Drake0056a422001-04-12 04:50:06 +0000256
257class WidgetResizeTestCase(SimpleWidgetTestCase):
258 def runTest(self):
259 self.widget.resize(100,150)
Fred Drake62a26692001-04-12 19:34:38 +0000260 self.failUnless(self.widget.size() == (100,150),
261 'wrong size after resize')
Fred Drake0056a422001-04-12 04:50:06 +0000262\end{verbatim}
263
264If the \method{setUp()} method raises an exception while the test is
265running, the framework will consider the test to have suffered an
266error, and the \method{runTest()} method will not be executed.
267
268Similarly, we can provide a \method{tearDown()} method that tidies up
269after the \method{runTest()} method has been run:
270
271\begin{verbatim}
272import unittest
273
274class SimpleWidgetTestCase(unittest.TestCase):
275 def setUp(self):
276 self.widget = Widget("The widget")
277
278 def tearDown(self):
279 self.widget.dispose()
280 self.widget = None
281\end{verbatim}
282
283If \method{setUp()} succeeded, the \method{tearDown()} method will be
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000284run whether \method{runTest()} succeeded or not.
Fred Drake0056a422001-04-12 04:50:06 +0000285
286Such a working environment for the testing code is called a
287\dfn{fixture}.
288
289Often, many small test cases will use the same fixture. In this case,
290we would end up subclassing \class{SimpleWidgetTestCase} into many
291small one-method classes such as
292\class{DefaultWidgetSizeTestCase}. This is time-consuming and
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000293discouraging, so in the same vein as JUnit, \module{unittest} provides
294a simpler mechanism:
Fred Drake0056a422001-04-12 04:50:06 +0000295
296\begin{verbatim}
297import unittest
298
299class WidgetTestCase(unittest.TestCase):
300 def setUp(self):
301 self.widget = Widget("The widget")
302
303 def tearDown(self):
304 self.widget.dispose()
305 self.widget = None
306
307 def testDefaultSize(self):
Fred Drake62a26692001-04-12 19:34:38 +0000308 self.failUnless(self.widget.size() == (50,50),
309 'incorrect default size')
Fred Drake0056a422001-04-12 04:50:06 +0000310
311 def testResize(self):
312 self.widget.resize(100,150)
Fred Drake62a26692001-04-12 19:34:38 +0000313 self.failUnless(self.widget.size() == (100,150),
314 'wrong size after resize')
Fred Drake0056a422001-04-12 04:50:06 +0000315\end{verbatim}
316
317Here we have not provided a \method{runTest()} method, but have
318instead provided two different test methods. Class instances will now
319each run one of the \method{test*()} methods, with \code{self.widget}
320created and destroyed separately for each instance. When creating an
321instance we must specify the test method it is to run. We do this by
322passing the method name in the constructor:
323
324\begin{verbatim}
325defaultSizeTestCase = WidgetTestCase("testDefaultSize")
326resizeTestCase = WidgetTestCase("testResize")
327\end{verbatim}
328
329Test case instances are grouped together according to the features
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000330they test. \module{unittest} provides a mechanism for this: the
331\dfn{test suite}, represented by \module{unittest}'s \class{TestSuite}
332class:
Fred Drake0056a422001-04-12 04:50:06 +0000333
334\begin{verbatim}
335widgetTestSuite = unittest.TestSuite()
336widgetTestSuite.addTest(WidgetTestCase("testDefaultSize"))
337widgetTestSuite.addTest(WidgetTestCase("testResize"))
338\end{verbatim}
339
340For the ease of running tests, as we will see later, it is a good
341idea to provide in each test module a callable object that returns a
342pre-built test suite:
343
344\begin{verbatim}
345def suite():
346 suite = unittest.TestSuite()
347 suite.addTest(WidgetTestCase("testDefaultSize"))
348 suite.addTest(WidgetTestCase("testResize"))
349 return suite
350\end{verbatim}
351
352or even:
353
354\begin{verbatim}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000355def suite():
356 tests = ["testDefaultSize", "testResize"]
Fred Drake0056a422001-04-12 04:50:06 +0000357
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000358 return unittest.TestSuite(map(WidgetTestCase, tests))
359\end{verbatim}
Fred Drake0056a422001-04-12 04:50:06 +0000360
361Since it is a common pattern to create a \class{TestCase} subclass
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000362with many similarly named test functions, \module{unittest} provides a
363\class{TestLoader} class that can be used to automate the process of
364creating a test suite and populating it with individual tests.
365For example,
Fred Drake0056a422001-04-12 04:50:06 +0000366
367\begin{verbatim}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000368suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)
Fred Drake0056a422001-04-12 04:50:06 +0000369\end{verbatim}
370
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000371will create a test suite that will run
372\code{WidgetTestCase.testDefaultSize()} and \code{WidgetTestCase.testResize}.
373\class{TestLoader} uses the \code{'test'} method name prefix to identify
374test methods automatically.
375
376Note that the order in which the various test cases will be run is
377determined by sorting the test function names with the built-in
378\function{cmp()} function.
Fred Drake0056a422001-04-12 04:50:06 +0000379
380Often it is desirable to group suites of test cases together, so as to
381run tests for the whole system at once. This is easy, since
382\class{TestSuite} instances can be added to a \class{TestSuite} just
383as \class{TestCase} instances can be added to a \class{TestSuite}:
384
385\begin{verbatim}
386suite1 = module1.TheTestSuite()
387suite2 = module2.TheTestSuite()
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000388alltests = unittest.TestSuite([suite1, suite2])
Fred Drake0056a422001-04-12 04:50:06 +0000389\end{verbatim}
390
391You can place the definitions of test cases and test suites in the
Raymond Hettingerd21fd7b2003-09-16 22:04:31 +0000392same modules as the code they are to test (such as \file{widget.py}),
Fred Drake0056a422001-04-12 04:50:06 +0000393but there are several advantages to placing the test code in a
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000394separate module, such as \file{test_widget.py}:
Fred Drake0056a422001-04-12 04:50:06 +0000395
396\begin{itemize}
397 \item The test module can be run standalone from the command line.
398 \item The test code can more easily be separated from shipped code.
Michael W. Hudsonaab02602003-02-10 19:21:16 +0000399 \item There is less temptation to change test code to fit the code
Fred Drake0056a422001-04-12 04:50:06 +0000400 it tests without a good reason.
401 \item Test code should be modified much less frequently than the
402 code it tests.
403 \item Tested code can be refactored more easily.
404 \item Tests for modules written in C must be in separate modules
405 anyway, so why not be consistent?
406 \item If the testing strategy changes, there is no need to change
407 the source code.
408\end{itemize}
409
Fred Drakeb9ad2282001-04-07 05:41:39 +0000410
411\subsection{Re-using old test code
412 \label{legacy-unit-tests}}
413
414Some users will find that they have existing test code that they would
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000415like to run from \module{unittest}, without converting every old test
416function to a \class{TestCase} subclass.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000417
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000418For this reason, \module{unittest} provides a \class{FunctionTestCase}
419class. This subclass of \class{TestCase} can be used to wrap an existing
420test function. Set-up and tear-down functions can also be provided.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000421
422Given the following test function:
423
424\begin{verbatim}
425def testSomething():
426 something = makeSomething()
427 assert something.name is not None
428 # ...
429\end{verbatim}
430
431one can create an equivalent test case instance as follows:
432
433\begin{verbatim}
434testcase = unittest.FunctionTestCase(testSomething)
435\end{verbatim}
436
437If there are additional set-up and tear-down methods that should be
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000438called as part of the test case's operation, they can also be provided
439like so:
Fred Drakeb9ad2282001-04-07 05:41:39 +0000440
441\begin{verbatim}
442testcase = unittest.FunctionTestCase(testSomething,
443 setUp=makeSomethingDB,
444 tearDown=deleteSomethingDB)
445\end{verbatim}
446
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000447To make migrating existing test suites easier, \module{unittest}
448supports tests raising \exception{AssertionError} to indicate test failure.
449However, it is recommended that you use the explicit
450\method{TestCase.fail*()} and \method{TestCase.assert*()} methods instead,
451as future versions of \module{unittest} may treat \exception{AssertionError}
452differently.
453
454\note{Even though \class{FunctionTestCase} can be used to quickly convert
455an existing test base over to a \module{unittest}-based system, this
456approach is not recommended. Taking the time to set up proper
457\class{TestCase} subclasses will make future test refactorings infinitely
458easier.}
459
Fred Drake0056a422001-04-12 04:50:06 +0000460
461
Fred Drakeb9ad2282001-04-07 05:41:39 +0000462\subsection{Classes and functions
463 \label{unittest-contents}}
464
465\begin{classdesc}{TestCase}{}
466 Instances of the \class{TestCase} class represent the smallest
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000467 testable units in the \module{unittest} universe. This class is
468 intended to be used as a base class, with specific tests being
469 implemented by concrete subclasses. This class implements the
470 interface needed by the test runner to allow it to drive the
471 test, and methods that the test code can use to check for and
472 report various kinds of failure.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000473\end{classdesc}
474
475\begin{classdesc}{FunctionTestCase}{testFunc\optional{,
Fred Drake62a26692001-04-12 19:34:38 +0000476 setUp\optional{, tearDown\optional{, description}}}}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000477 This class implements the portion of the \class{TestCase} interface
478 which allows the test runner to drive the test, but does not provide
479 the methods which test code can use to check and report errors.
480 This is used to create test cases using legacy test code, allowing
481 it to be integrated into a \refmodule{unittest}-based test
482 framework.
483\end{classdesc}
484
Fred Drake29be7012001-04-10 22:25:06 +0000485\begin{classdesc}{TestSuite}{\optional{tests}}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000486 This class represents an aggregation of individual tests cases and
487 test suites. The class presents the interface needed by the test
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000488 runner to allow it to be run as any other test case. Running a
489 \class{TestSuite} instance is the same as iterating over the suite,
490 running each test individually.
491
492 If \var{tests} is given, it must be an iterable of individual test cases or
493 other test suites that will be used to build the suite initially.
494 Additional methods are provided to add test cases and suites to the
495 collection later on.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000496\end{classdesc}
497
498\begin{classdesc}{TestLoader}{}
Fred Drake29be7012001-04-10 22:25:06 +0000499 This class is responsible for loading tests according to various
500 criteria and returning them wrapped in a \class{TestSuite}.
501 It can load all tests within a given module or \class{TestCase}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000502 subclass.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000503\end{classdesc}
504
Fred Drake62a26692001-04-12 19:34:38 +0000505\begin{datadesc}{defaultTestLoader}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000506 Instance of the \class{TestLoader} class intended to be shared. If no
Fred Drake62a26692001-04-12 19:34:38 +0000507 customization of the \class{TestLoader} is needed, this instance can
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000508 be used instead of repeatedly creating new instances.
Fred Drake62a26692001-04-12 19:34:38 +0000509\end{datadesc}
510
Fred Drakeb9ad2282001-04-07 05:41:39 +0000511\begin{classdesc}{TextTestRunner}{\optional{stream\optional{,
512 descriptions\optional{, verbosity}}}}
Fred Drake29be7012001-04-10 22:25:06 +0000513 A basic test runner implementation which prints results on standard
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000514 error. It has a few configurable parameters, but is essentially
Fred Drake29be7012001-04-10 22:25:06 +0000515 very simple. Graphical applications which run test suites should
516 provide alternate implementations.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000517\end{classdesc}
518
519\begin{funcdesc}{main}{\optional{module\optional{,
520 defaultTest\optional{, argv\optional{,
521 testRunner\optional{, testRunner}}}}}}
Fred Drake0056a422001-04-12 04:50:06 +0000522 A command-line program that runs a set of tests; this is primarily
523 for making test modules conveniently executable. The simplest use
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000524 for this function is to include the following line at the end of a
525 test script:
Fred Drakeb9ad2282001-04-07 05:41:39 +0000526
527\begin{verbatim}
528if __name__ == '__main__':
529 unittest.main()
530\end{verbatim}
531\end{funcdesc}
532
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000533In some cases, the existing tests may have been written using the
Fred Drakeae55d5f2003-12-31 04:34:50 +0000534\refmodule{doctest} module. If so, that module provides a
Raymond Hettingerd21fd7b2003-09-16 22:04:31 +0000535\class{DocTestSuite} class that can automatically build
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000536\class{unittest.TestSuite} instances from the existing
537\module{doctest}-based tests.
Raymond Hettingerd21fd7b2003-09-16 22:04:31 +0000538\versionadded{2.3}
539
Fred Drakeb9ad2282001-04-07 05:41:39 +0000540
541\subsection{TestCase Objects
542 \label{testcase-objects}}
543
Fred Drake29be7012001-04-10 22:25:06 +0000544Each \class{TestCase} instance represents a single test, but each
545concrete subclass may be used to define multiple tests --- the
546concrete class represents a single test fixture. The fixture is
547created and cleaned up for each test case.
548
549\class{TestCase} instances provide three groups of methods: one group
550used to run the test, another used by the test implementation to
551check conditions and report failures, and some inquiry methods
552allowing information about the test itself to be gathered.
553
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000554Methods in the first group (running the test) are:
Fred Drake29be7012001-04-10 22:25:06 +0000555
556\begin{methoddesc}[TestCase]{setUp}{}
557 Method called to prepare the test fixture. This is called
558 immediately before calling the test method; any exception raised by
559 this method will be considered an error rather than a test failure.
560 The default implementation does nothing.
561\end{methoddesc}
562
Fred Drake29be7012001-04-10 22:25:06 +0000563\begin{methoddesc}[TestCase]{tearDown}{}
564 Method called immediately after the test method has been called and
565 the result recorded. This is called even if the test method raised
566 an exception, so the implementation in subclasses may need to be
567 particularly careful about checking internal state. Any exception
568 raised by this method will be considered an error rather than a test
Fred Drake62a26692001-04-12 19:34:38 +0000569 failure. This method will only be called if the \method{setUp()}
570 succeeds, regardless of the outcome of the test method.
571 The default implementation does nothing.
572\end{methoddesc}
573
574\begin{methoddesc}[TestCase]{run}{\optional{result}}
575 Run the test, collecting the result into the test result object
Fred Drakeae55d5f2003-12-31 04:34:50 +0000576 passed as \var{result}. If \var{result} is omitted or \constant{None},
Fred Drake62a26692001-04-12 19:34:38 +0000577 a temporary result object is created and used, but is not made
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000578 available to the caller.
579
580 The same effect may be had by simply calling the \class{TestCase}
581 instance.
Fred Drake29be7012001-04-10 22:25:06 +0000582\end{methoddesc}
583
584\begin{methoddesc}[TestCase]{debug}{}
585 Run the test without collecting the result. This allows exceptions
Raymond Hettinger68804312005-01-01 00:28:46 +0000586 raised by the test to be propagated to the caller, and can be used
Fred Drake29be7012001-04-10 22:25:06 +0000587 to support running tests under a debugger.
588\end{methoddesc}
589
590
Fred Drake0056a422001-04-12 04:50:06 +0000591The test code can use any of the following methods to check for and
Fred Drake62a26692001-04-12 19:34:38 +0000592report failures.
Fred Drake29be7012001-04-10 22:25:06 +0000593
Fred Drake62a26692001-04-12 19:34:38 +0000594\begin{methoddesc}[TestCase]{assert_}{expr\optional{, msg}}
595\methodline{failUnless}{expr\optional{, msg}}
596 Signal a test failure if \var{expr} is false; the explanation for
597 the error will be \var{msg} if given, otherwise it will be
Fred Drakeae55d5f2003-12-31 04:34:50 +0000598 \constant{None}.
Fred Drake29be7012001-04-10 22:25:06 +0000599\end{methoddesc}
600
Fred Drake62a26692001-04-12 19:34:38 +0000601\begin{methoddesc}[TestCase]{assertEqual}{first, second\optional{, msg}}
602\methodline{failUnlessEqual}{first, second\optional{, msg}}
Fred Drake29be7012001-04-10 22:25:06 +0000603 Test that \var{first} and \var{second} are equal. If the values do
604 not compare equal, the test will fail with the explanation given by
Fred Drakeae55d5f2003-12-31 04:34:50 +0000605 \var{msg}, or \constant{None}. Note that using \method{failUnlessEqual()}
Fred Drake29be7012001-04-10 22:25:06 +0000606 improves upon doing the comparison as the first parameter to
Fred Drake62a26692001-04-12 19:34:38 +0000607 \method{failUnless()}: the default value for \var{msg} can be
Fred Drake29be7012001-04-10 22:25:06 +0000608 computed to include representations of both \var{first} and
609 \var{second}.
610\end{methoddesc}
611
Fred Drake62a26692001-04-12 19:34:38 +0000612\begin{methoddesc}[TestCase]{assertNotEqual}{first, second\optional{, msg}}
613\methodline{failIfEqual}{first, second\optional{, msg}}
Fred Drake29be7012001-04-10 22:25:06 +0000614 Test that \var{first} and \var{second} are not equal. If the values
615 do compare equal, the test will fail with the explanation given by
Fred Drakeae55d5f2003-12-31 04:34:50 +0000616 \var{msg}, or \constant{None}. Note that using \method{failIfEqual()}
Fred Drake29be7012001-04-10 22:25:06 +0000617 improves upon doing the comparison as the first parameter to
618 \method{failUnless()} is that the default value for \var{msg} can be
619 computed to include representations of both \var{first} and
620 \var{second}.
621\end{methoddesc}
622
Raymond Hettingerc7b07692002-12-29 17:59:24 +0000623\begin{methoddesc}[TestCase]{assertAlmostEqual}{first, second\optional{,
624 places\optional{, msg}}}
625\methodline{failUnlessAlmostEqual}{first, second\optional{,
626 places\optional{, msg}}}
627 Test that \var{first} and \var{second} are approximately equal
628 by computing the difference, rounding to the given number of \var{places},
629 and comparing to zero. Note that comparing a given number of decimal places
630 is not the same as comparing a given number of significant digits.
631 If the values do not compare equal, the test will fail with the explanation
Fred Drakeae55d5f2003-12-31 04:34:50 +0000632 given by \var{msg}, or \constant{None}.
Raymond Hettingerc7b07692002-12-29 17:59:24 +0000633\end{methoddesc}
634
635\begin{methoddesc}[TestCase]{assertNotAlmostEqual}{first, second\optional{,
636 places\optional{, msg}}}
637\methodline{failIfAlmostEqual}{first, second\optional{,
638 places\optional{, msg}}}
639 Test that \var{first} and \var{second} are not approximately equal
640 by computing the difference, rounding to the given number of \var{places},
641 and comparing to zero. Note that comparing a given number of decimal places
642 is not the same as comparing a given number of significant digits.
643 If the values do not compare equal, the test will fail with the explanation
Fred Drakeae55d5f2003-12-31 04:34:50 +0000644 given by \var{msg}, or \constant{None}.
Raymond Hettingerc7b07692002-12-29 17:59:24 +0000645\end{methoddesc}
646
Fred Drake62a26692001-04-12 19:34:38 +0000647\begin{methoddesc}[TestCase]{assertRaises}{exception, callable, \moreargs}
648\methodline{failUnlessRaises}{exception, callable, \moreargs}
649 Test that an exception is raised when \var{callable} is called with
650 any positional or keyword arguments that are also passed to
651 \method{assertRaises()}. The test passes if \var{exception} is
652 raised, is an error if another exception is raised, or fails if no
653 exception is raised. To catch any of a group of exceptions, a tuple
654 containing the exception classes may be passed as \var{exception}.
655\end{methoddesc}
656
Fred Drake29be7012001-04-10 22:25:06 +0000657\begin{methoddesc}[TestCase]{failIf}{expr\optional{, msg}}
Fred Drake0056a422001-04-12 04:50:06 +0000658 The inverse of the \method{failUnless()} method is the
Fred Drake62a26692001-04-12 19:34:38 +0000659 \method{failIf()} method. This signals a test failure if \var{expr}
Fred Drakeae55d5f2003-12-31 04:34:50 +0000660 is true, with \var{msg} or \constant{None} for the error message.
Fred Drake29be7012001-04-10 22:25:06 +0000661\end{methoddesc}
662
663\begin{methoddesc}[TestCase]{fail}{\optional{msg}}
Fred Drake62a26692001-04-12 19:34:38 +0000664 Signals a test failure unconditionally, with \var{msg} or
Fred Drakeae55d5f2003-12-31 04:34:50 +0000665 \constant{None} for the error message.
Fred Drake29be7012001-04-10 22:25:06 +0000666\end{methoddesc}
667
Fred Drake62a26692001-04-12 19:34:38 +0000668\begin{memberdesc}[TestCase]{failureException}
669 This class attribute gives the exception raised by the
670 \method{test()} method. If a test framework needs to use a
671 specialized exception, possibly to carry additional information, it
672 must subclass this exception in order to ``play fair'' with the
673 framework. The initial value of this attribute is
674 \exception{AssertionError}.
675\end{memberdesc}
676
Fred Drake29be7012001-04-10 22:25:06 +0000677
678Testing frameworks can use the following methods to collect
679information on the test:
680
681\begin{methoddesc}[TestCase]{countTestCases}{}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000682 Return the number of tests represented by this test object. For
683 \class{TestCase} instances, this will always be \code{1}.
Fred Drake29be7012001-04-10 22:25:06 +0000684\end{methoddesc}
685
686\begin{methoddesc}[TestCase]{defaultTestResult}{}
687 Return the default type of test result object to be used to run this
688 test.
689\end{methoddesc}
690
691\begin{methoddesc}[TestCase]{id}{}
692 Return a string identifying the specific test case. This is usually
693 the full name of the test method, including the module and class
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000694 name.
Fred Drake29be7012001-04-10 22:25:06 +0000695\end{methoddesc}
696
697\begin{methoddesc}[TestCase]{shortDescription}{}
Fred Drakeae55d5f2003-12-31 04:34:50 +0000698 Returns a one-line description of the test, or \constant{None} if no
Fred Drake29be7012001-04-10 22:25:06 +0000699 description has been provided. The default implementation of this
700 method returns the first line of the test method's docstring, if
Fred Drakeae55d5f2003-12-31 04:34:50 +0000701 available, or \constant{None}.
Fred Drake29be7012001-04-10 22:25:06 +0000702\end{methoddesc}
703
Fred Drakeb9ad2282001-04-07 05:41:39 +0000704
705\subsection{TestSuite Objects
706 \label{testsuite-objects}}
707
708\class{TestSuite} objects behave much like \class{TestCase} objects,
709except they do not actually implement a test. Instead, they are used
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000710to aggregate tests into groups of tests that should be run together.
711Some additional methods are available to add tests to \class{TestSuite}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000712instances:
713
714\begin{methoddesc}[TestSuite]{addTest}{test}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000715 Add a \class{TestCase} or \class{TestSuite} to the suite.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000716\end{methoddesc}
717
718\begin{methoddesc}[TestSuite]{addTests}{tests}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000719 Add all the tests from an iterable of \class{TestCase} and
Fred Drakeb9ad2282001-04-07 05:41:39 +0000720 \class{TestSuite} instances to this test suite.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000721
722 This is equivalent to iterating over \var{tests}, calling
723 \method{addTest()} for each element.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000724\end{methoddesc}
725
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000726\class{TestSuite} shares the following methods with \class{TestCase}:
Fred Drake4d17b302001-09-06 15:51:56 +0000727
728\begin{methoddesc}[TestSuite]{run}{result}
729 Run the tests associated with this suite, collecting the result into
730 the test result object passed as \var{result}. Note that unlike
731 \method{TestCase.run()}, \method{TestSuite.run()} requires the
732 result object to be passed in.
733\end{methoddesc}
734
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000735\begin{methoddesc}[TestSuite]{debug}{}
736 Run the tests associated with this suite without collecting the result.
737 This allows exceptions raised by the test to be propagated to the caller
738 and can be used to support running tests under a debugger.
739\end{methoddesc}
740
741\begin{methoddesc}[TestSuite]{countTestCases}{}
742 Return the number of tests represented by this test object, including
743 all individual tests and sub-suites.
744\end{methoddesc}
745
Fred Drake4d17b302001-09-06 15:51:56 +0000746In the typical usage of a \class{TestSuite} object, the \method{run()}
747method is invoked by a \class{TestRunner} rather than by the end-user
748test harness.
749
Fred Drakeb9ad2282001-04-07 05:41:39 +0000750
751\subsection{TestResult Objects
752 \label{testresult-objects}}
753
754A \class{TestResult} object stores the results of a set of tests. The
755\class{TestCase} and \class{TestSuite} classes ensure that results are
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000756properly recorded; test authors do not need to worry about recording the
Fred Drakeb9ad2282001-04-07 05:41:39 +0000757outcome of tests.
758
759Testing frameworks built on top of \refmodule{unittest} may want
760access to the \class{TestResult} object generated by running a set of
761tests for reporting purposes; a \class{TestResult} instance is
762returned by the \method{TestRunner.run()} method for this purpose.
763
764Each instance holds the total number of tests run, and collections of
765failures and errors that occurred among those test runs. The
766collections contain tuples of \code{(\var{testcase},
Fred Drake387c8b52002-07-02 22:34:44 +0000767\var{traceback})}, where \var{traceback} is a string containing a
768formatted version of the traceback for the exception.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000769
770\class{TestResult} instances have the following attributes that will
771be of interest when inspecting the results of running a set of tests:
772
773\begin{memberdesc}[TestResult]{errors}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000774 A list containing 2-tuples of \class{TestCase} instances and
775 formatted tracebacks. Each tuple represents a test which raised an
776 unexpected exception.
Fred Drakec4126172002-07-02 22:46:42 +0000777 \versionchanged[Contains formatted tracebacks instead of
778 \function{sys.exc_info()} results]{2.2}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000779\end{memberdesc}
780
781\begin{memberdesc}[TestResult]{failures}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000782 A list containing 2-tuples of \class{TestCase} instances and
783 formatted tracebacks. Each tuple represents a test where a failure
784 was explicitly signalled using the \method{TestCase.fail*()} or
785 \method{TestCase.assert*()} methods.
Fred Drakec4126172002-07-02 22:46:42 +0000786 \versionchanged[Contains formatted tracebacks instead of
787 \function{sys.exc_info()} results]{2.2}
Fred Drakeb9ad2282001-04-07 05:41:39 +0000788\end{memberdesc}
789
790\begin{memberdesc}[TestResult]{testsRun}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000791 The total number of tests run so far.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000792\end{memberdesc}
793
794\begin{methoddesc}[TestResult]{wasSuccessful}{}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000795 Returns \constant{True} if all tests run so far have passed,
796 otherwise returns \constant{False}.
797\end{methoddesc}
798
799\begin{methoddesc}[TestResult]{stop}{}
800 This method can be called to signal that the set of tests being run
801 should be aborted by setting the \class{TestResult}'s \code{shouldStop}
802 attribute to \constant{True}. \class{TestRunner} objects should respect
803 this flag and return without running any additional tests.
804
805 For example, this feature is used by the \class{TextTestRunner} class
806 to stop the test framework when the user signals an interrupt from
807 the keyboard. Interactive tools which provide \class{TestRunner}
808 implementations can use this in a similar manner.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000809\end{methoddesc}
810
811
812The following methods of the \class{TestResult} class are used to
Martin v. Löwis7bdc4842003-09-20 11:09:28 +0000813maintain the internal data structures, and may be extended in
Fred Drakeb9ad2282001-04-07 05:41:39 +0000814subclasses to support additional reporting requirements. This is
Fred Drake8ee679f2001-07-14 02:50:55 +0000815particularly useful in building tools which support interactive
Fred Drakeb9ad2282001-04-07 05:41:39 +0000816reporting while tests are being run.
817
818\begin{methoddesc}[TestResult]{startTest}{test}
819 Called when the test case \var{test} is about to be run.
820\end{methoddesc}
821
822\begin{methoddesc}[TestResult]{stopTest}{test}
823 Called when the test case \var{test} has been executed, regardless
824 of the outcome.
825\end{methoddesc}
826
827\begin{methoddesc}[TestResult]{addError}{test, err}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000828 Called when the test case \var{test} raises an unexpected exception
829 \var{err} is a tuple of the form returned by \function{sys.exc_info()}:
830 \code{(\var{type}, \var{value}, \var{traceback})}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000831\end{methoddesc}
832
833\begin{methoddesc}[TestResult]{addFailure}{test, err}
Fred Drake62a26692001-04-12 19:34:38 +0000834 Called when the test case \var{test} signals a failure.
Fred Drake0056a422001-04-12 04:50:06 +0000835 \var{err} is a tuple of the form returned by
836 \function{sys.exc_info()}: \code{(\var{type}, \var{value},
837 \var{traceback})}.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000838\end{methoddesc}
839
840\begin{methoddesc}[TestResult]{addSuccess}{test}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000841 Called when the test case \var{test} succeeds.
Fred Drakeb9ad2282001-04-07 05:41:39 +0000842\end{methoddesc}
843
844
Fred Drake62a26692001-04-12 19:34:38 +0000845
846\subsection{TestLoader Objects
847 \label{testloader-objects}}
848
849The \class{TestLoader} class is used to create test suites from
850classes and modules. Normally, there is no need to create an instance
851of this class; the \refmodule{unittest} module provides an instance
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000852that can be shared as \code{unittest.defaultTestLoader}.
853Using a subclass or instance, however, allows customization of some
Fred Drake62a26692001-04-12 19:34:38 +0000854configurable properties.
855
856\class{TestLoader} objects have the following methods:
857
858\begin{methoddesc}[TestLoader]{loadTestsFromTestCase}{testCaseClass}
859 Return a suite of all tests cases contained in the
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000860 \class{TestCase}-derived \class{testCaseClass}.
Fred Drake62a26692001-04-12 19:34:38 +0000861\end{methoddesc}
862
863\begin{methoddesc}[TestLoader]{loadTestsFromModule}{module}
864 Return a suite of all tests cases contained in the given module.
865 This method searches \var{module} for classes derived from
866 \class{TestCase} and creates an instance of the class for each test
867 method defined for the class.
868
Fred Drake0aa811c2001-10-20 04:24:09 +0000869 \warning{While using a hierarchy of
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000870 \class{TestCase}-derived classes can be convenient in sharing
Fred Drake62a26692001-04-12 19:34:38 +0000871 fixtures and helper functions, defining test methods on base classes
872 that are not intended to be instantiated directly does not play well
873 with this method. Doing so, however, can be useful when the
Fred Drake0aa811c2001-10-20 04:24:09 +0000874 fixtures are different and defined in subclasses.}
Fred Drake62a26692001-04-12 19:34:38 +0000875\end{methoddesc}
876
877\begin{methoddesc}[TestLoader]{loadTestsFromName}{name\optional{, module}}
878 Return a suite of all tests cases given a string specifier.
879
Fred Drake4d17b302001-09-06 15:51:56 +0000880 The specifier \var{name} is a ``dotted name'' that may resolve
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000881 either to a module, a test case class, a \class{TestSuite} instance,
882 a test method within a test case class, or a callable object which
883 returns a \class{TestCase} or \class{TestSuite} instance.
884
885 For example, if you have a module \module{SampleTests} containing a
886 \class{TestCase}-derived class \class{SampleTestCase} with three test
887 methods (\method{test_one()}, \method{test_two()}, and
888 \method{test_three()}), the specifier \code{'SampleTests.SampleTestCase'}
889 would cause this method to return a suite which will run all three test
890 methods. Using the specifier \code{'SampleTests.SampleTestCase.test_two'}
891 would cause it to return a test suite which will run only the
Fred Drake4d17b302001-09-06 15:51:56 +0000892 \method{test_two()} test method. The specifier can refer to modules
893 and packages which have not been imported; they will be imported as
894 a side-effect.
Fred Drake62a26692001-04-12 19:34:38 +0000895
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000896 The method optionally resolves \var{name} relative to the given
897 \var{module}.
Fred Drake62a26692001-04-12 19:34:38 +0000898\end{methoddesc}
899
900\begin{methoddesc}[TestLoader]{loadTestsFromNames}{names\optional{, module}}
901 Similar to \method{loadTestsFromName()}, but takes a sequence of
902 names rather than a single name. The return value is a test suite
903 which supports all the tests defined for each name.
904\end{methoddesc}
905
906\begin{methoddesc}[TestLoader]{getTestCaseNames}{testCaseClass}
907 Return a sorted sequence of method names found within
908 \var{testCaseClass}.
909\end{methoddesc}
910
911
912The following attributes of a \class{TestLoader} can be configured
913either by subclassing or assignment on an instance:
914
915\begin{memberdesc}[TestLoader]{testMethodPrefix}
916 String giving the prefix of method names which will be interpreted
917 as test methods. The default value is \code{'test'}.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000918
919 This affects \method{getTestCaseNames()} and all the
920 \method{loadTestsFrom*()} methods.
Fred Drake62a26692001-04-12 19:34:38 +0000921\end{memberdesc}
922
923\begin{memberdesc}[TestLoader]{sortTestMethodsUsing}
924 Function to be used to compare method names when sorting them in
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000925 \method{getTestCaseNames()} and all the \method{loadTestsFrom*()} methods.
926 The default value is the built-in \function{cmp()} function; the attribute
927 can also be set to \constant{None} to disable the sort.
Fred Drake62a26692001-04-12 19:34:38 +0000928\end{memberdesc}
929
930\begin{memberdesc}[TestLoader]{suiteClass}
931 Callable object that constructs a test suite from a list of tests.
932 No methods on the resulting object are needed. The default value is
933 the \class{TestSuite} class.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000934
935 This affects all the \method{loadTestsFrom*()} methods.
Fred Drake62a26692001-04-12 19:34:38 +0000936\end{memberdesc}