Skip to content

Commit 5121faa

Browse files
[3.12] gh-89392: Remove support of test_main() in libregrtest (GH-108876) (#108897)
[3.12] gh-89392: Remove support of test_main() in libregrtest (GH-108876). (cherry picked from commit 04a0830) Co-authored-by: Alex Waygood <[email protected]>
1 parent 8c551a7 commit 5121faa

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Lib/test/libregrtest/runtest.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,10 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
345345

346346
the_module = importlib.import_module(abstest)
347347

348-
# If the test has a test_main, that will run the appropriate
349-
# tests. If not, use normal unittest test loading.
350-
test_func = getattr(the_module, "test_main", None)
351-
if test_func is None:
352-
test_func = functools.partial(_test_module, the_module)
348+
if hasattr(the_module, "test_main"):
349+
# https://github.com/python/cpython/issues/89392
350+
raise Exception(f"Module {result.test_name} defines test_main() which is no longer supported by regrtest")
351+
test_func = functools.partial(_test_module, the_module)
353352

354353
try:
355354
with save_env(ns, result.test_name):

Lib/test/test_regrtest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1678,9 +1678,9 @@ def my_function():
16781678
7948648
16791679
"""
16801680
1681-
def test_main():
1682-
testmod = sys.modules[__name__]
1683-
return support.run_doctest(testmod)
1681+
def load_tests(loader, tests, pattern):
1682+
tests.addTest(doctest.DocTestSuite())
1683+
return tests
16841684
''')
16851685
testname = self.create_test(code=code)
16861686

@@ -1689,7 +1689,7 @@ def test_main():
16891689
self.check_executed_tests(output, [testname],
16901690
failed=[testname],
16911691
randomize=True,
1692-
stats=TestStats(3, 2, 0))
1692+
stats=TestStats(1, 1, 0))
16931693

16941694

16951695
class TestUtils(unittest.TestCase):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Removed support of ``test_main()`` function in tests. They now always use
2+
normal unittest test runner.

0 commit comments

Comments
 (0)