blob: 496c40040b6bf4b9d0bd53a5de44723a6f3f2db1 [file] [log] [blame]
Neal Norwitzdeaba572002-11-27 15:47:10 +00001+++++++++++++++++++++++++++++++
2Writing Python Regression Tests
3+++++++++++++++++++++++++++++++
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +00004
Neal Norwitzdeaba572002-11-27 15:47:10 +00005:Author: Skip Montanaro
6:Contact: skip@mojam.com
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +00007
8Introduction
Neal Norwitzdeaba572002-11-27 15:47:10 +00009============
Skip Montanaro47c60ec2000-06-30 06:08:35 +000010
11If you add a new module to Python or modify the functionality of an existing
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +000012module, you should write one or more test cases to exercise that new
Fred Drakea6daad22001-05-23 04:57:49 +000013functionality. There are different ways to do this within the regression
14testing facility provided with Python; any particular test should use only
15one of these options. Each option requires writing a test module using the
Walter Dörwald88af4df2003-02-03 20:22:27 +000016conventions of the selected option:
Skip Montanaro47c60ec2000-06-30 06:08:35 +000017
Neal Norwitzdeaba572002-11-27 15:47:10 +000018 - PyUnit_ based tests
19 - doctest_ based tests
Fred Drakea6daad22001-05-23 04:57:49 +000020 - "traditional" Python test modules
21
22Regardless of the mechanics of the testing approach you choose,
23you will be writing unit tests (isolated tests of functions and objects
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +000024defined by the module) using white box techniques. Unlike black box
25testing, where you only have the external interfaces to guide your test case
26writing, in white box testing you can see the code being tested and tailor
27your test cases to exercise it more completely. In particular, you will be
28able to refer to the C and Python code in the CVS repository when writing
29your regression test cases.
Skip Montanaro47c60ec2000-06-30 06:08:35 +000030
Neal Norwitzdeaba572002-11-27 15:47:10 +000031.. _PyUnit:
32.. _unittest: http://www.python.org/doc/current/lib/module-unittest.html
33.. _doctest: http://www.python.org/doc/current/lib/module-doctest.html
Tim Petersf5f6c432001-05-23 07:46:36 +000034
Fred Drakea6daad22001-05-23 04:57:49 +000035PyUnit based tests
Neal Norwitzdeaba572002-11-27 15:47:10 +000036------------------
37The PyUnit_ framework is based on the ideas of unit testing as espoused
38by Kent Beck and the `Extreme Programming`_ (XP) movement. The specific
39interface provided by the framework is tightly based on the JUnit_
Fred Drakea6daad22001-05-23 04:57:49 +000040Java implementation of Beck's original SmallTalk test framework. Please
Neal Norwitzdeaba572002-11-27 15:47:10 +000041see the documentation of the unittest_ module for detailed information on
Fred Drakea6daad22001-05-23 04:57:49 +000042the interface and general guidelines on writing PyUnit based tests.
43
Walter Dörwald88af4df2003-02-03 20:22:27 +000044The test_support helper module provides two functions for use by
Fred Drakea6daad22001-05-23 04:57:49 +000045PyUnit based tests in the Python regression testing framework:
Neal Norwitzdeaba572002-11-27 15:47:10 +000046
47- ``run_unittest()`` takes a ``unittest.TestCase`` derived class as a
48 parameter and runs the tests defined in that class
49
50- ``run_suite()`` takes a populated ``TestSuite`` instance and runs the
51 tests
52
53``run_suite()`` is preferred because unittest files typically grow multiple
54test classes, and you might as well be prepared.
Barry Warsaw5ca53742002-04-23 21:39:00 +000055
56All test methods in the Python regression framework have names that
Neal Norwitzdeaba572002-11-27 15:47:10 +000057start with "``test_``" and use lower-case names with words separated with
Barry Warsaw5ca53742002-04-23 21:39:00 +000058underscores.
Fred Drakeb2ad1c82001-09-28 20:05:25 +000059
Guido van Rossum1c486542002-08-22 20:08:14 +000060Test methods should *not* have docstrings! The unittest module prints
61the docstring if there is one, but otherwise prints the function name
62and the full class name. When there's a problem with a test, the
63latter information makes it easier to find the source for the test
64than the docstring.
65
Fred Drakeb2ad1c82001-09-28 20:05:25 +000066All PyUnit-based tests in the Python test suite use boilerplate that
Neal Norwitzdeaba572002-11-27 15:47:10 +000067looks like this (with minor variations)::
Fred Drakeb2ad1c82001-09-28 20:05:25 +000068
69 import unittest
Barry Warsaw04f357c2002-07-23 19:04:11 +000070 from test import test_support
Fred Drakeb2ad1c82001-09-28 20:05:25 +000071
Barry Warsaw5ca53742002-04-23 21:39:00 +000072 class MyTestCase1(unittest.TestCase):
Guido van Rossum1c486542002-08-22 20:08:14 +000073
74 # Define setUp and tearDown only if needed
75
76 def setUp(self):
77 unittest.TestCase.setUp(self)
78 ... additional initialization...
79
80 def tearDown(self):
81 ... additional finalization...
82 unittest.TestCase.tearDown(self)
83
84 def test_feature_one(self):
85 # Testing feature one
86 ...unit test for feature one...
87
88 def test_feature_two(self):
89 # Testing feature two
90 ...unit test for feature two...
91
92 ...etc...
Fred Drakeb2ad1c82001-09-28 20:05:25 +000093
Barry Warsaw5ca53742002-04-23 21:39:00 +000094 class MyTestCase2(unittest.TestCase):
Guido van Rossum1c486542002-08-22 20:08:14 +000095 ...same structure as MyTestCase1...
96
97 ...etc...
Barry Warsaw5ca53742002-04-23 21:39:00 +000098
Fred Drakeb2ad1c82001-09-28 20:05:25 +000099 def test_main():
Guido van Rossum1c486542002-08-22 20:08:14 +0000100 suite = unittest.TestSuite()
101 suite.addTest(unittest.makeSuite(MyTestCase1))
102 suite.addTest(unittest.makeSuite(MyTestCase2))
103 ...add more suites...
Barry Warsaw5ca53742002-04-23 21:39:00 +0000104 test_support.run_suite(suite)
Fred Drakeb2ad1c82001-09-28 20:05:25 +0000105
106 if __name__ == "__main__":
107 test_main()
108
109This has the advantage that it allows the unittest module to be used
110as a script to run individual tests as well as working well with the
111regrtest framework.
Fred Drakea6daad22001-05-23 04:57:49 +0000112
Neal Norwitzdeaba572002-11-27 15:47:10 +0000113.. _Extreme Programming: http://www.extremeprogramming.org/
114.. _JUnit: http://www.junit.org/
Tim Petersf5f6c432001-05-23 07:46:36 +0000115
Fred Drakea6daad22001-05-23 04:57:49 +0000116doctest based tests
Neal Norwitzdeaba572002-11-27 15:47:10 +0000117-------------------
118Tests written to use doctest_ are actually part of the docstrings for
Fred Drakea6daad22001-05-23 04:57:49 +0000119the module being tested. Each test is written as a display of an
120interactive session, including the Python prompts, statements that would
121be typed by the user, and the output of those statements (including
Tim Petersf5f6c432001-05-23 07:46:36 +0000122tracebacks, although only the exception msg needs to be retained then).
123The module in the test package is simply a wrapper that causes doctest
124to run over the tests in the module. The test for the difflib module
Neal Norwitzdeaba572002-11-27 15:47:10 +0000125provides a convenient example::
Fred Drakea6daad22001-05-23 04:57:49 +0000126
Barry Warsaw1bfab7b2002-07-23 19:13:45 +0000127 import difflib
128 from test import test_support
Tim Petersa0a62222001-09-09 06:12:01 +0000129 test_support.run_doctest(difflib)
Tim Petersf5f6c432001-05-23 07:46:36 +0000130
131If the test is successful, nothing is written to stdout (so you should not
132create a corresponding output/test_difflib file), but running regrtest
Tim Petersa0a62222001-09-09 06:12:01 +0000133with -v will give a detailed report, the same as if passing -v to doctest.
134
135A second argument can be passed to run_doctest to tell doctest to search
Neal Norwitzdeaba572002-11-27 15:47:10 +0000136``sys.argv`` for -v instead of using test_support's idea of verbosity. This
Tim Petersa0a62222001-09-09 06:12:01 +0000137is useful for writing doctest-based tests that aren't simply running a
138doctest'ed Lib module, but contain the doctests themselves. Then at
139times you may want to run such a test directly as a doctest, independent
140of the regrtest framework. The tail end of test_descrtut.py is a good
Neal Norwitzdeaba572002-11-27 15:47:10 +0000141example::
Tim Petersa0a62222001-09-09 06:12:01 +0000142
143 def test_main(verbose=None):
Barry Warsaw1bfab7b2002-07-23 19:13:45 +0000144 from test import test_support, test_descrtut
145 test_support.run_doctest(test_descrtut, verbose)
Tim Petersa0a62222001-09-09 06:12:01 +0000146
147 if __name__ == "__main__":
148 test_main(1)
149
Neal Norwitzdeaba572002-11-27 15:47:10 +0000150If run via regrtest, ``test_main()`` is called (by regrtest) without
151specifying verbose, and then test_support's idea of verbosity is used. But
152when run directly, ``test_main(1)`` is called, and then doctest's idea of
153verbosity is used.
Fred Drakea6daad22001-05-23 04:57:49 +0000154
155See the documentation for the doctest module for information on
156writing tests using the doctest framework.
157
158"traditional" Python test modules
Neal Norwitzdeaba572002-11-27 15:47:10 +0000159---------------------------------
Fred Drakea6daad22001-05-23 04:57:49 +0000160The mechanics of how the "traditional" test system operates are fairly
161straightforward. When a test case is run, the output is compared with the
162expected output that is stored in .../Lib/test/output. If the test runs to
163completion and the actual and expected outputs match, the test succeeds, if
Neal Norwitzdeaba572002-11-27 15:47:10 +0000164not, it fails. If an ``ImportError`` or ``test_support.TestSkipped`` error
165is raised, the test is not run.
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000166
167Executing Test Cases
Neal Norwitzdeaba572002-11-27 15:47:10 +0000168====================
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000169If you are writing test cases for module spam, you need to create a file
Tim Petersf5f6c432001-05-23 07:46:36 +0000170in .../Lib/test named test_spam.py. In addition, if the tests are expected
171to write to stdout during a successful run, you also need to create an
172expected output file in .../Lib/test/output named test_spam ("..."
173represents the top-level directory in the Python source tree, the directory
174containing the configure script). If needed, generate the initial version
Neal Norwitzdeaba572002-11-27 15:47:10 +0000175of the test output file by executing::
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000176
177 ./python Lib/test/regrtest.py -g test_spam.py
178
Tim Petersf5f6c432001-05-23 07:46:36 +0000179from the top-level directory.
Fred Drakea6daad22001-05-23 04:57:49 +0000180
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000181Any time you modify test_spam.py you need to generate a new expected
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000182output file. Don't forget to desk check the generated output to make sure
Tim Petersf5f6c432001-05-23 07:46:36 +0000183it's really what you expected to find! All in all it's usually better
184not to have an expected-out file (note that doctest- and unittest-based
185tests do not).
186
187To run a single test after modifying a module, simply run regrtest.py
Neal Norwitzdeaba572002-11-27 15:47:10 +0000188without the -g flag::
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000189
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000190 ./python Lib/test/regrtest.py test_spam.py
191
192While debugging a regression test, you can of course execute it
Neal Norwitzdeaba572002-11-27 15:47:10 +0000193independently of the regression testing framework and see what it prints::
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000194
195 ./python Lib/test/test_spam.py
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000196
Tim Petersf5f6c432001-05-23 07:46:36 +0000197To run the entire test suite:
198
Neal Norwitzdeaba572002-11-27 15:47:10 +0000199- [UNIX, + other platforms where "make" works] Make the "test" target at the
200 top level::
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000201
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000202 make test
203
Neal Norwitzdeaba572002-11-27 15:47:10 +0000204- [WINDOWS] Run rt.bat from your PCBuild directory. Read the comments at
205 the top of rt.bat for the use of special -d, -O and -q options processed
206 by rt.bat.
Tim Petersf5f6c432001-05-23 07:46:36 +0000207
Neal Norwitzdeaba572002-11-27 15:47:10 +0000208- [OTHER] You can simply execute the two runs of regrtest (optimized and
209 non-optimized) directly::
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000210
211 ./python Lib/test/regrtest.py
212 ./python -O Lib/test/regrtest.py
213
Tim Petersf5f6c432001-05-23 07:46:36 +0000214But note that this way picks up whatever .pyc and .pyo files happen to be
215around. The makefile and rt.bat ways run the tests twice, the first time
216removing all .pyc and .pyo files from the subtree rooted at Lib/.
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000217
218Test cases generate output based upon values computed by the test code.
219When executed, regrtest.py compares the actual output generated by executing
220the test case with the expected output and reports success or failure. It
221stands to reason that if the actual and expected outputs are to match, they
222must not contain any machine dependencies. This means your test cases
223should not print out absolute machine addresses (e.g. the return value of
224the id() builtin function) or floating point numbers with large numbers of
225significant digits (unless you understand what you are doing!).
226
227
228Test Case Writing Tips
Neal Norwitzdeaba572002-11-27 15:47:10 +0000229======================
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000230Writing good test cases is a skilled task and is too complex to discuss in
231detail in this short document. Many books have been written on the subject.
Neal Norwitzdeaba572002-11-27 15:47:10 +0000232I'll show my age by suggesting that Glenford Myers' `"The Art of Software
233Testing"`_, published in 1979, is still the best introduction to the subject
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000234available. It is short (177 pages), easy to read, and discusses the major
235elements of software testing, though its publication predates the
236object-oriented software revolution, so doesn't cover that subject at all.
237Unfortunately, it is very expensive (about $100 new). If you can borrow it
238or find it used (around $20), I strongly urge you to pick up a copy.
239
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000240The most important goal when writing test cases is to break things. A test
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000241case that doesn't uncover a bug is much less valuable than one that does.
242In designing test cases you should pay attention to the following:
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000243
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000244 * Your test cases should exercise all the functions and objects defined
245 in the module, not just the ones meant to be called by users of your
246 module. This may require you to write test code that uses the module
247 in ways you don't expect (explicitly calling internal functions, for
248 example - see test_atexit.py).
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000249
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000250 * You should consider any boundary values that may tickle exceptional
251 conditions (e.g. if you were writing regression tests for division,
252 you might well want to generate tests with numerators and denominators
253 at the limits of floating point and integer numbers on the machine
254 performing the tests as well as a denominator of zero).
Skip Montanaro47c60ec2000-06-30 06:08:35 +0000255
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000256 * You should exercise as many paths through the code as possible. This
257 may not always be possible, but is a goal to strive for. In
258 particular, when considering if statements (or their equivalent), you
259 want to create test cases that exercise both the true and false
260 branches. For loops, you should create test cases that exercise the
261 loop zero, one and multiple times.
262
263 * You should test with obviously invalid input. If you know that a
264 function requires an integer input, try calling it with other types of
265 objects to see how it responds.
266
267 * You should test with obviously out-of-range input. If the domain of a
268 function is only defined for positive integers, try calling it with a
269 negative integer.
270
271 * If you are going to fix a bug that wasn't uncovered by an existing
272 test, try to write a test case that exposes the bug (preferably before
273 fixing it).
274
Fred Drake44b6bd22000-10-23 16:37:14 +0000275 * If you need to create a temporary file, you can use the filename in
Neal Norwitzdeaba572002-11-27 15:47:10 +0000276 ``test_support.TESTFN`` to do so. It is important to remove the file
Fred Drake44b6bd22000-10-23 16:37:14 +0000277 when done; other tests should be able to use the name without cleaning
278 up after your test.
279
Neal Norwitzdeaba572002-11-27 15:47:10 +0000280.. _"The Art of Software Testing":
281 http://www.amazon.com/exec/obidos/ISBN=0471043281
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000282
283Regression Test Writing Rules
Neal Norwitzdeaba572002-11-27 15:47:10 +0000284=============================
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000285Each test case is different. There is no "standard" form for a Python
Tim Petersf5f6c432001-05-23 07:46:36 +0000286regression test case, though there are some general rules (note that
Neal Norwitzdeaba572002-11-27 15:47:10 +0000287these mostly apply only to the "classic" tests; unittest_- and doctest_-
288based tests should follow the conventions natural to those frameworks)::
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000289
Neal Norwitzdeaba572002-11-27 15:47:10 +0000290 * If your test case detects a failure, raise ``TestFailed`` (found in
291 ``test.test_support``).
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000292
293 * Import everything you'll need as early as possible.
294
295 * If you'll be importing objects from a module that is at least
296 partially platform-dependent, only import those objects you need for
Neal Norwitzdeaba572002-11-27 15:47:10 +0000297 the current test case to avoid spurious ``ImportError`` exceptions
298 that prevent the test from running to completion.
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000299
Neal Norwitzdeaba572002-11-27 15:47:10 +0000300 * Print all your test case results using the ``print`` statement. For
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000301 non-fatal errors, print an error message (or omit a successful
302 completion print) to indicate the failure, but proceed instead of
Neal Norwitzdeaba572002-11-27 15:47:10 +0000303 raising ``TestFailed``.
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000304
Neal Norwitzdeaba572002-11-27 15:47:10 +0000305 * Use ``assert`` sparingly, if at all. It's usually better to just print
Tim Petersa48b5262000-08-23 05:28:45 +0000306 what you got, and rely on regrtest's got-vs-expected comparison to
Neal Norwitzdeaba572002-11-27 15:47:10 +0000307 catch deviations from what you expect. ``assert`` statements aren't
Tim Petersa48b5262000-08-23 05:28:45 +0000308 executed at all when regrtest is run in -O mode; and, because they
309 cause the test to stop immediately, can lead to a long & tedious
310 test-fix, test-fix, test-fix, ... cycle when things are badly broken
311 (and note that "badly broken" often includes running the test suite
312 for the first time on new platforms or under new implementations of
313 the language).
314
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000315Miscellaneous
Neal Norwitzdeaba572002-11-27 15:47:10 +0000316=============
Barry Warsaw1bfab7b2002-07-23 19:13:45 +0000317There is a test_support module in the test package you can import for
Neal Norwitzdeaba572002-11-27 15:47:10 +0000318your test case. Import this module using either::
Barry Warsaw04f357c2002-07-23 19:04:11 +0000319
320 import test.test_support
321
Neal Norwitzdeaba572002-11-27 15:47:10 +0000322or::
Barry Warsaw04f357c2002-07-23 19:04:11 +0000323
324 from test import test_support
325
326test_support provides the following useful objects:
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000327
Neal Norwitzdeaba572002-11-27 15:47:10 +0000328 * ``TestFailed`` - raise this exception when your regression test detects
329 a failure.
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000330
Neal Norwitzdeaba572002-11-27 15:47:10 +0000331 * ``TestSkipped`` - raise this if the test could not be run because the
Fred Drake62c53dd2000-08-21 16:55:57 +0000332 platform doesn't offer all the required facilities (like large
333 file support), even if all the required modules are available.
334
Brett Cannone6b70332003-04-30 01:42:35 +0000335 * ``ResourceDenied`` - this is raised when a test requires a resource that
336 is not available. Primarily used by 'requires'.
337
Neal Norwitzdeaba572002-11-27 15:47:10 +0000338 * ``verbose`` - you can use this variable to control print output. Many
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000339 modules use it. Search for "verbose" in the test_*.py files to see
340 lots of examples.
341
Brett Cannone6b70332003-04-30 01:42:35 +0000342 * ``forget(module_name)`` - attempts to cause Python to "forget" that it
343 loaded a module and erase any PYC files.
344
345 * ``is_resource_enabled(resource)`` - Returns a boolean based on whether
346 the resource is enabled or not.
347
348 * ``requires(resource [, msg])`` - if the required resource is not
349 available the ResourceDenied exception is raised.
350
Neal Norwitzdeaba572002-11-27 15:47:10 +0000351 * ``verify(condition, reason='test failed')``. Use this instead of::
Tim Petersf5f6c432001-05-23 07:46:36 +0000352
353 assert condition[, reason]
354
Neal Norwitzdeaba572002-11-27 15:47:10 +0000355 ``verify()`` has two advantages over ``assert``: it works even in -O
356 mode, and it raises ``TestFailed`` on failure instead of
357 ``AssertionError``.
Tim Petersf5f6c432001-05-23 07:46:36 +0000358
Brett Cannone6b70332003-04-30 01:42:35 +0000359 * ``have_unicode`` - true if Unicode is available, false otherwise.
360
361 * ``is_jython`` - true if the interpreter is Jython, false otherwise.
362
Neal Norwitzdeaba572002-11-27 15:47:10 +0000363 * ``TESTFN`` - a string that should always be used as the filename when
364 you need to create a temp file. Also use ``try``/``finally`` to
365 ensure that your temp files are deleted before your test completes.
366 Note that you cannot unlink an open file on all operating systems, so
367 also be sure to close temp files before trying to unlink them.
Tim Petersf5f6c432001-05-23 07:46:36 +0000368
Neal Norwitzdeaba572002-11-27 15:47:10 +0000369 * ``sortdict(dict)`` - acts like ``repr(dict.items())``, but sorts the
370 items first. This is important when printing a dict value, because
371 the order of items produced by ``dict.items()`` is not defined by the
Tim Petersf5f6c432001-05-23 07:46:36 +0000372 language.
373
Neal Norwitzdeaba572002-11-27 15:47:10 +0000374 * ``findfile(file)`` - you can call this function to locate a file
375 somewhere along sys.path or in the Lib/test tree - see
376 test_linuxaudiodev.py for an example of its use.
Tim Petersf5f6c432001-05-23 07:46:36 +0000377
Neal Norwitzdeaba572002-11-27 15:47:10 +0000378 * ``fcmp(x,y)`` - you can call this function to compare two floating
379 point numbers when you expect them to only be approximately equal
380 withing a fuzz factor (``test_support.FUZZ``, which defaults to 1e-6).
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000381
Brett Cannone6b70332003-04-30 01:42:35 +0000382 * ``check_syntax(statement)`` - make sure that the statement is *not*
383 correct Python syntax.
384
Tim Petersa48b5262000-08-23 05:28:45 +0000385
Skip Montanaroe9e5dcd2000-07-19 17:19:49 +0000386Python and C statement coverage results are currently available at
387
388 http://www.musi-cal.com/~skip/python/Python/dist/src/
389
390As of this writing (July, 2000) these results are being generated nightly.
391You can refer to the summaries and the test coverage output files to see
392where coverage is adequate or lacking and write test cases to beef up the
393coverage.
Tim Petersf5f6c432001-05-23 07:46:36 +0000394
Tim Petersf5f6c432001-05-23 07:46:36 +0000395Some Non-Obvious regrtest Features
Neal Norwitzdeaba572002-11-27 15:47:10 +0000396==================================
Tim Petersf5f6c432001-05-23 07:46:36 +0000397 * Automagic test detection: When you create a new test file
398 test_spam.py, you do not need to modify regrtest (or anything else)
399 to advertise its existence. regrtest searches for and runs all
400 modules in the test directory with names of the form test_xxx.py.
401
402 * Miranda output: If, when running test_spam.py, regrtest does not
403 find an expected-output file test/output/test_spam, regrtest
404 pretends that it did find one, containing the single line
405
406 test_spam
407
408 This allows new tests that don't expect to print anything to stdout
409 to not bother creating expected-output files.
410
411 * Two-stage testing: To run test_spam.py, regrtest imports test_spam
412 as a module. Most tests run to completion as a side-effect of
413 getting imported. After importing test_spam, regrtest also executes
Neal Norwitzdeaba572002-11-27 15:47:10 +0000414 ``test_spam.test_main()``, if test_spam has a ``test_main`` attribute.
Fred Drakeb2ad1c82001-09-28 20:05:25 +0000415 This is rarely required with the "traditional" Python tests, and
416 you shouldn't create a module global with name test_main unless
417 you're specifically exploiting this gimmick. This usage does
418 prove useful with PyUnit-based tests as well, however; defining
Neal Norwitzdeaba572002-11-27 15:47:10 +0000419 a ``test_main()`` which is run by regrtest and a script-stub in the
420 test module ("``if __name__ == '__main__': test_main()``") allows
Fred Drakeb2ad1c82001-09-28 20:05:25 +0000421 the test to be used like any other Python test and also work
422 with the unittest.py-as-a-script approach, allowing a developer
423 to run specific tests from the command line.