Skip to content

Commit

Permalink
gh-89392: Remove support of test_main() in libregrtest (GH-108876)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Sep 5, 2023
1 parent 1170d5a commit 04a0830
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
13 changes: 5 additions & 8 deletions Lib/test/libregrtest/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,11 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:

test_mod = importlib.import_module(module_name)

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

try:
with save_env(ns, result.test_name):
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,9 +1803,9 @@ def my_function():
7948648
"""
def test_main():
testmod = sys.modules[__name__]
return support.run_doctest(testmod)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests
''')
testname = self.create_test(code=code)

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


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

0 comments on commit 04a0830

Please sign in to comment.