Skip to content

Commit 492e1ff

Browse files
[3.11] gh-89392: Remove support of test_main() in libregrtest (GH-108876) (GH-108898)
(cherry picked from commit 04a0830)
1 parent 562c168 commit 492e1ff

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
@@ -341,11 +341,10 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
341341

342342
the_module = importlib.import_module(abstest)
343343

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

350349
try:
351350
with save_env(ns, result.test_name):

Lib/test/test_regrtest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1680,9 +1680,9 @@ def my_function():
16801680
7948648
16811681
"""
16821682
1683-
def test_main():
1684-
testmod = sys.modules[__name__]
1685-
return support.run_doctest(testmod)
1683+
def load_tests(loader, tests, pattern):
1684+
tests.addTest(doctest.DocTestSuite())
1685+
return tests
16861686
''')
16871687
testname = self.create_test(code=code)
16881688

@@ -1691,7 +1691,7 @@ def test_main():
16911691
self.check_executed_tests(output, [testname],
16921692
failed=[testname],
16931693
randomize=True,
1694-
stats=TestStats(3, 2, 0))
1694+
stats=TestStats(1, 1, 0))
16951695

16961696

16971697
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)