Skip to content

gh-158681: Document that regrtest rejects test_main() and loads unittest suites - #158682

Open
bazhil wants to merge 8 commits into
python:mainfrom
bazhil:doc-regrtest-unittest-loader
Open

bazhil wants to merge 8 commits into
python:mainfrom
bazhil:doc-regrtest-unittest-loader

Conversation

@bazhil

@bazhil bazhil commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

#158681

Doc/library/test.rst said that python -m test calls a module-level test_main() when it exists, and otherwise loads tests with unittest.TestLoader.loadTestsFromModule. It also told readers to call test.support.reap_children() at the end of test_main. The docstring of reap_children() said the same thing.

libregrtest does not call test_main(). If the imported module defines it, Lib/test/libregrtest/single.py raises Exception. regrtest reports the module as failed with an uncaught exception (stderr: test <name> crashed; summary: failed (uncaught exception)). Tests are loaded with loadTestsFromModule, which collects TestCase classes and, when the module defines load_tests, runs the suite that function returns. Packages use load_tests, usually via test.support.load_package_tests, to add tests from submodules. reap_children() is called from setUp(), tearDown(), and tearDownModule().

The runner is unchanged. This updates the library page and the reap_children() docstring.

@python-cla-bot

python-cla-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

read-the-docs-community Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Comment thread Misc/NEWS.d/next/Documentation/2026-10-03-21-19-14.gh-issue-158681.fpovlg.rst Outdated
@aisk aisk added the skip news label Oct 4, 2026
@aisk

aisk commented Oct 4, 2026

Copy link
Copy Markdown
Member

The commit email doesn't seem to be a valid address. Please use a valid one.

@bazhil
bazhil force-pushed the doc-regrtest-unittest-loader branch from fd30727 to 58b6171 Compare October 4, 2026 16:51
@bazhil

bazhil commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

The commit email doesn't seem to be a valid address. Please use a valid one.

Fixed

Comment thread Doc/library/test.rst Outdated
names of tests to execute may also be passed to the script. Specifying a single
:mod:`!test` package. It does this by finding modules and packages whose names
start with ``test_``, importing each one, and loading its tests with
:meth:`unittest.TestLoader.loadTestsFromModule`. The loader collects

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too much unittest detail for this section, what about linking to 'load_tests Protocol' instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread Doc/library/test.rst Outdated
This will help ensure that no extra children (zombies) stick around to
hog resources and create problems when looking for refleaks.
Call this from a test's :meth:`~unittest.TestCase.setUp`,
:meth:`~unittest.TestCase.tearDown`, or from ``tearDownModule`` when the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:meth:`~unittest.TestCase.tearDown`, or from ``tearDownModule`` when the
:meth:`~unittest.TestCase.tearDown`, or ``tearDownModule`` when the

Duplicate "from".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@bazhil
bazhil force-pushed the doc-regrtest-unittest-loader branch from 58b6171 to aabe5ea Compare October 7, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants