Skip to content

Commit 04a0830

Browse files
gh-89392: Remove support of test_main() in libregrtest (GH-108876)
1 parent 1170d5a commit 04a0830

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

Lib/test/libregrtest/runtest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,11 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
440440

441441
test_mod = importlib.import_module(module_name)
442442

443-
# If the test has a test_main, that will run the appropriate
444-
# tests. If not, use normal unittest test runner.
445-
test_main = getattr(test_mod, "test_main", None)
446-
if test_main is not None:
447-
test_func = test_main
448-
else:
449-
def test_func():
450-
return run_unittest(test_mod)
443+
if hasattr(test_mod, "test_main"):
444+
# https://github.com/python/cpython/issues/89392
445+
raise Exception("Module {result.test_name} defines test_main() which is no longer supported by regrtest")
446+
def test_func():
447+
return run_unittest(test_mod)
451448

452449
try:
453450
with save_env(ns, result.test_name):

Lib/test/test_regrtest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,9 @@ def my_function():
18031803
7948648
18041804
"""
18051805
1806-
def test_main():
1807-
testmod = sys.modules[__name__]
1808-
return support.run_doctest(testmod)
1806+
def load_tests(loader, tests, pattern):
1807+
tests.addTest(doctest.DocTestSuite())
1808+
return tests
18091809
''')
18101810
testname = self.create_test(code=code)
18111811

@@ -1814,7 +1814,7 @@ def test_main():
18141814
self.check_executed_tests(output, [testname],
18151815
failed=[testname],
18161816
randomize=True,
1817-
stats=TestStats(4, 2, 1))
1817+
stats=TestStats(1, 1, 0))
18181818

18191819

18201820
class TestUtils(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
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)