]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146410: Add --pythoninfo option to regrtest (#146413)
authorVictor Stinner <vstinner@python.org>
Thu, 26 Mar 2026 09:56:38 +0000 (10:56 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Mar 2026 09:56:38 +0000 (10:56 +0100)
* Android now runs tests with --pythoninfo to dump build information.
* Add display_title() function.

Android/android.py
Lib/test/libregrtest/cmdline.py
Lib/test/libregrtest/main.py
Lib/test/libregrtest/utils.py
Lib/test/pythoninfo.py
Lib/test/test_regrtest.py

index b644be9cc64c7af25a19b06ef2c6cef0f5d85079..317875ef336e0e8c3682c410845ebd1504dc1238 100755 (executable)
@@ -628,7 +628,8 @@ async def gradle_task(context):
             # Randomization is disabled because order-dependent failures are
             # much less likely to pass on a rerun in single-process mode.
             "-m", "test",
-            f"--{context.ci_mode}-ci", "--single-process", "--no-randomize"
+            f"--{context.ci_mode}-ci", "--single-process", "--no-randomize",
+            "--pythoninfo",
         ]
 
     if not any(arg in context.args for arg in ["-c", "-m"]):
index 2c404f6d80bcf39fe570e03cc51f3685c3820d53..ea26cc849f818280da8c9388aff5098bec69445e 100644 (file)
@@ -393,6 +393,8 @@ def _create_parser():
                        help='remove old test_python_* directories')
     group.add_argument('--bisect', action='store_true',
                        help='if some tests fail, run test.bisect_cmd on them')
+    group.add_argument('--pythoninfo', action='store_true',
+                       help="run python -m test.pythoninfo before tests")
     group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
                        action='store_false',
                        help="internal option, don't use it")
index d8b9605ea4984321c010139e4491e027bebe801a..ac82541059cc62826b6fe7fe105012c4ec50d0f2 100644 (file)
@@ -26,7 +26,7 @@ from .utils import (
     strip_py_suffix, count, format_duration,
     printlist, get_temp_dir, get_work_dir, exit_timeout,
     display_header, cleanup_temp_dir, print_warning,
-    is_cross_compiled, get_host_runner,
+    is_cross_compiled, get_host_runner, display_title,
     EXIT_TIMEOUT)
 
 
@@ -126,6 +126,7 @@ class Regrtest:
         self.coverage: bool = ns.trace
         self.coverage_dir: StrPath | None = ns.coverdir
         self._tmp_dir: StrPath | None = ns.tempdir
+        self.pythoninfo: bool = ns.pythoninfo
 
         # Randomize
         self.randomize: bool = ns.randomize
@@ -322,9 +323,7 @@ class Regrtest:
         title = f"Bisect {test}"
         if progress:
             title = f"{title} ({progress})"
-        print(title)
-        print("#" * len(title))
-        print()
+        display_title(title)
 
         cmd = runtests.create_python_cmd()
         cmd.extend([
@@ -345,9 +344,7 @@ class Regrtest:
         exitcode = proc.returncode
 
         title = f"{title}: exit code {exitcode}"
-        print(title)
-        print("#" * len(title))
-        print(flush=True)
+        display_title(title)
 
         if exitcode:
             print(f"Bisect failed with exit code {exitcode}")
@@ -752,6 +749,15 @@ class Regrtest:
             )
         return self._tmp_dir
 
+    def run_pythoninfo(self):
+        from test import pythoninfo
+        try:
+            pythoninfo.main()
+        except SystemExit:
+            # Ignore non-zero exit code on purpose
+            pass
+        print()
+
     def main(self, tests: TestList | None = None) -> NoReturn:
         if self.want_add_python_opts:
             self._add_python_opts()
@@ -765,6 +771,9 @@ class Regrtest:
         if self.want_wait:
             input("Press any key to continue...")
 
+        if self.pythoninfo:
+            self.run_pythoninfo()
+
         setup_test_dir(self.test_dir)
         selected, tests = self.find_tests(tests)
 
index 3946a76e6add29cdfd16fb2f7bc8c91bd1cae356..00703d6c074855bbdbc1fef65f54861c4a339ead 100644 (file)
@@ -746,3 +746,9 @@ def _sanitize_xml_replace(regs):
 
 def sanitize_xml(text: str) -> str:
     return ILLEGAL_XML_CHARS_RE.sub(_sanitize_xml_replace, text)
+
+
+def display_title(title):
+    print(title)
+    print("#" * len(title))
+    print(flush=True)
index 219fbb4bb1bbe2b5e26d2ea22c26eee3ea0158d1..7f735d75b318e7f71c8d43754cb6f5af9f0b1b32 100644 (file)
@@ -1103,9 +1103,9 @@ def collect_info(info):
 
 
 def dump_info(info, file=None):
-    title = "Python debug information"
+    title = "Python build information"
     print(title)
-    print("=" * len(title))
+    print("#" * len(title))
     print()
 
     infos = info.get_infos()
index fc6694d489fb0faf34527609b12fde05503a0dc9..0946289328ccda2121d15608a0c78dc3906d47ff 100644 (file)
@@ -571,6 +571,13 @@ class ParseArgsTestCase(unittest.TestCase):
         self.assertEqual(regrtest.num_workers, 0)
         self.assertTrue(regrtest.single_process)
 
+    def test_pythoninfo(self):
+        ns = self.parse_args([])
+        self.assertFalse(ns.pythoninfo)
+
+        ns = self.parse_args(['--pythoninfo'])
+        self.assertTrue(ns.pythoninfo)
+
 
 @dataclasses.dataclass(slots=True)
 class Rerun:
@@ -2427,6 +2434,11 @@ class ArgsTestCase(BaseTestCase):
         self.assertNotIn('test_re', tests)
         self.assertEqual(len(tests), len(pgo_tests) - 1)
 
+    def test_pythoninfo(self):
+        testname = self.create_test()
+        output = self.run_tests('--pythoninfo', testname)
+        self.assertIn("Python build information", output)
+
 
 class TestUtils(unittest.TestCase):
     def test_format_duration(self):