Skip to content

Commit b6bc98e

Browse files
bazhilmiss-islington
authored andcommitted
gh-158681: Document that regrtest no longer supports test_main() (GH-158682)
(cherry picked from commit 75ce53d) Co-authored-by: Ilya Bazhenov <31971067+bazhil@users.noreply.github.com>
1 parent 31e88bc commit b6bc98e

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

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

882884
.. function:: reap_children()
883885

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

888892

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

‎Lib/test/support/__init__.py‎

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

15371537

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

0 commit comments

Comments
 (0)