@@ -36,12 +36,32 @@ Java implementation of Beck's original SmallTalk test framework. Please
3636see the documentation of the unittest module for detailed information on
3737the interface and general guidelines on writing PyUnit based tests.
3838
39- The test_support helper module provides a single function for use by
39+ The test_support helper module provides a two functions for use by
4040PyUnit based tests in the Python regression testing framework:
4141run_unittest() takes a unittest.TestCase derived class as a parameter
42- and runs the tests defined in that class. All test methods in the
43- Python regression framework have names that start with "test_" and use
44- lower-case names with words separated with underscores.
42+ and runs the tests defined in that class, and run_suite() takes a
43+ populated TestSuite instance and runs the tests.. All test methods in
44+ the Python regression framework have names that start with "test_" and
45+ use lower-case names with words separated with underscores.
46+
47+ All PyUnit-based tests in the Python test suite use boilerplate that
48+ looks like this:
49+
50+ import unittest
51+ import test_support
52+
53+ class MyTestCase(unittest.TestCase):
54+ # define test methods here...
55+
56+ def test_main():
57+ test_support.run_unittest(MyTestCase)
58+
59+ if __name__ == "__main__":
60+ test_main()
61+
62+ This has the advantage that it allows the unittest module to be used
63+ as a script to run individual tests as well as working well with the
64+ regrtest framework.
4565
4666
4767doctest based tests
@@ -341,8 +361,12 @@ Some Non-Obvious regrtest Features
341361 as a module. Most tests run to completion as a side-effect of
342362 getting imported. After importing test_spam, regrtest also executes
343363 test_spam.test_main(), if test_spam has a "test_main" attribute.
344- This is rarely needed, and you shouldn't create a module global
345- with name test_main unless you're specifically exploiting this
346- gimmick. In such cases, please put a comment saying so near your
347- def test_main, because this feature is so rarely used it's not
348- obvious when reading the test code.
364+ This is rarely required with the "traditional" Python tests, and
365+ you shouldn't create a module global with name test_main unless
366+ you're specifically exploiting this gimmick. This usage does
367+ prove useful with PyUnit-based tests as well, however; defining
368+ a test_main() which is run by regrtest and a script-stub in the
369+ test module ("if __name__ == '__main__': test_main()") allows
370+ the test to be used like any other Python test and also work
371+ with the unittest.py-as-a-script approach, allowing a developer
372+ to run specific tests from the command line.
0 commit comments