summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-09-05 11:18:41 (GMT)
committerGitHub <noreply@github.com>2023-09-05 11:18:41 (GMT)
commit5121faabd1b3733a1198a18fa5df540eeb2475f6 (patch)
treeb0f56490072986f0cfdd9157864410b9890b0f33
parent8c551a7f2a7e9b8e3c811f669b915419851c2c8e (diff)
downloadcpython-5121faabd1b3733a1198a18fa5df540eeb2475f6.zip
cpython-5121faabd1b3733a1198a18fa5df540eeb2475f6.tar.gz
cpython-5121faabd1b3733a1198a18fa5df540eeb2475f6.tar.bz2
[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 04a0830b00879efe057e3dfe75e9aa9c0caf1a26) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
-rw-r--r--Lib/test/libregrtest/runtest.py9
-rw-r--r--Lib/test/test_regrtest.py8
-rw-r--r--Misc/NEWS.d/next/Tests/2023-09-04-15-18-14.gh-issue-89392.8A4T5p.rst2
3 files changed, 10 insertions, 9 deletions
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
index 6fa6069..2c30269 100644
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -345,11 +345,10 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
the_module = importlib.import_module(abstest)
- # If the test has a test_main, that will run the appropriate
- # tests. If not, use normal unittest test loading.
- test_func = getattr(the_module, "test_main", None)
- if test_func is None:
- test_func = functools.partial(_test_module, the_module)
+ if hasattr(the_module, "test_main"):
+ # https://github.com/python/cpython/issues/89392
+ raise Exception(f"Module {result.test_name} defines test_main() which is no longer supported by regrtest")
+ test_func = functools.partial(_test_module, the_module)
try:
with save_env(ns, result.test_name):
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 14f5a96..68f7136 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -1678,9 +1678,9 @@ class ArgsTestCase(BaseTestCase):
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)
@@ -1689,7 +1689,7 @@ class ArgsTestCase(BaseTestCase):
self.check_executed_tests(output, [testname],
failed=[testname],
randomize=True,
- stats=TestStats(3, 2, 0))
+ stats=TestStats(1, 1, 0))
class TestUtils(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Tests/2023-09-04-15-18-14.gh-issue-89392.8A4T5p.rst b/Misc/NEWS.d/next/Tests/2023-09-04-15-18-14.gh-issue-89392.8A4T5p.rst
new file mode 100644
index 0000000..e1dea8e
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2023-09-04-15-18-14.gh-issue-89392.8A4T5p.rst
@@ -0,0 +1,2 @@
+Removed support of ``test_main()`` function in tests. They now always use
+normal unittest test runner.