Skip to content

Commit 75ce53d

Browse files
authored
gh-158681: Document that regrtest no longer supports test_main() (#158682)
1 parent 9cb7a5b commit 75ce53d

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎Doc/library/test.rst‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ 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`. See the
171+
:ref:`load_tests protocol <load_tests-protocol>` for how a module or package
172+
can customize what is loaded. Defining a module-level ``test_main()`` function
173+
is not supported and causes the test to fail. The names of tests to
174+
execute may also be passed to the script. Specifying a single
173175
regression test (:program:`python -m test test_spam`) will minimize output and
174176
only print whether the test passed or failed.
175177

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

883885
.. function:: reap_children()
884886

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.
887+
Call this from :meth:`~unittest.TestCase.setUp`,
888+
:meth:`~unittest.TestCase.tearDown`, or ``tearDownModule()`` in tests
889+
that start subprocesses. This will help ensure that no extra children
890+
(zombies) stick around to hog resources and create problems when looking
891+
for refleaks.
888892

889893

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

‎Lib/test/support/__init__.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,10 +1621,10 @@ def set_environment_altered(reason):
16211621

16221622

16231623
def reap_children():
1624-
"""Use this function at the end of test_main() whenever sub-processes
1625-
are started. This will help ensure that no extra children (zombies)
1626-
stick around to hog resources and create problems when looking
1627-
for refleaks.
1624+
"""Call this from setUp(), tearDown(), or tearDownModule() in tests
1625+
that start subprocesses. This will help ensure that no extra children
1626+
(zombies) stick around to hog resources and create problems when
1627+
looking for refleaks.
16281628
"""
16291629
# Need os.waitpid(-1, os.WNOHANG): Windows is not supported
16301630
if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):

0 commit comments

Comments
 (0)