Skip to content

Commit 74deff9

Browse files
[3.14] gh-158681: Document that regrtest no longer supports test_main() (GH-158682) (#159574)
(cherry picked from commit 75ce53d) Co-authored-by: Ilya Bazhenov <31971067+bazhil@users.noreply.github.com>
1 parent 527e9a2 commit 74deff9

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
@@ -167,11 +167,13 @@ test suite, thanks to the :option:`-m` option: :program:`python -m test`. Under
167167
the hood, it uses :mod:`!test.regrtest`; the call :program:`python -m
168168
test.regrtest` used in previous Python versions still works. Running the
169169
script by itself automatically starts running all regression tests in the
170-
:mod:`!test` package. It does this by finding all modules in the package whose
171-
name starts with ``test_``, importing them, and executing the function
172-
:func:`test_main` if present or loading the tests via
173-
unittest.TestLoader.loadTestsFromModule if ``test_main`` does not exist. The
174-
names of tests to execute may also be passed to the script. Specifying a single
170+
:mod:`!test` package. It does this by finding modules and packages whose names
171+
start with ``test_``, importing each one, and loading its tests with
172+
:meth:`unittest.TestLoader.loadTestsFromModule`. See the
173+
:ref:`load_tests protocol <load_tests-protocol>` for how a module or package
174+
can customize what is loaded. Defining a module-level ``test_main()`` function
175+
is not supported and causes the test to fail. The names of tests to
176+
execute may also be passed to the script. Specifying a single
175177
regression test (:program:`python -m test test_spam`) will minimize output and
176178
only print whether the test passed or failed.
177179

@@ -883,9 +885,11 @@ The :mod:`!test.support` module defines the following functions:
883885

884886
.. function:: reap_children()
885887

886-
Use this at the end of ``test_main`` whenever sub-processes are started.
887-
This will help ensure that no extra children (zombies) stick around to
888-
hog resources and create problems when looking for refleaks.
888+
Call this from :meth:`~unittest.TestCase.setUp`,
889+
:meth:`~unittest.TestCase.tearDown`, or ``tearDownModule()`` in tests
890+
that start subprocesses. This will help ensure that no extra children
891+
(zombies) stick around to hog resources and create problems when looking
892+
for refleaks.
889893

890894

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

‎Lib/test/support/__init__.py‎

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

14541454

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

0 commit comments

Comments
 (0)