Skip to content

Commit af68b2e

Browse files
committed
Document that regrtest loads tests with unittest and rejects test_main().
1 parent 0906d2a commit af68b2e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎Doc/library/test.rst‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,16 @@ test suite, thanks to the :option:`-m` option: :program:`python -m test`. Under
165165
the hood, it uses :mod:`!test.regrtest`; the call :program:`python -m
166166
test.regrtest` used in previous Python versions still works. Running the
167167
script by itself automatically starts running all regression tests in the
168-
:mod:`!test` package. It does this by finding all modules in the package whose
169-
name starts with ``test_``, importing them, and executing the function
170-
:func:`test_main` if present or loading the tests via
171-
unittest.TestLoader.loadTestsFromModule if ``test_main`` does not exist. The
172-
names of tests to execute may also be passed to the script. Specifying a single
168+
:mod:`!test` package. It does this by finding modules and packages whose names
169+
start with ``test_``, importing each one, and loading its tests with
170+
:meth:`unittest.TestLoader.loadTestsFromModule`. The loader collects
171+
:class:`unittest.TestCase` tests defined in the module. If the module defines
172+
``load_tests``, the loader calls it with that suite and runs the suite the
173+
function returns. Test packages use ``load_tests``, often via
174+
:func:`test.support.load_package_tests`, to add tests discovered in
175+
submodules. A module-level ``test_main()`` function is not called. If a test
176+
module defines ``test_main``, :mod:`!test.regrtest` fails that test. The names of
177+
tests to execute may also be passed to the script. Specifying a single
173178
regression test (:program:`python -m test test_spam`) will minimize output and
174179
only print whether the test passed or failed.
175180

@@ -882,9 +887,11 @@ The :mod:`!test.support` module defines the following functions:
882887

883888
.. function:: reap_children()
884889

885-
Use this at the end of ``test_main`` whenever sub-processes are started.
886-
This will help ensure that no extra children (zombies) stick around to
887-
hog resources and create problems when looking for refleaks.
890+
Call this from a test's :meth:`~unittest.TestCase.setUp`,
891+
:meth:`~unittest.TestCase.tearDown`, or from ``tearDownModule`` when the
892+
test starts subprocesses. This will help ensure that no extra children
893+
(zombies) stick around to hog resources and create problems when looking
894+
for refleaks.
888895

889896

890897
.. function:: get_attribute(obj, name)

0 commit comments

Comments
 (0)