Skip to content

Commit c5d3599

Browse files
vstinnermiss-islington
authored andcommitted
gh-146410: Add --pythoninfo option to regrtest (GH-146413)
* Android now runs tests with --pythoninfo to dump build information. * Add display_title() function. (cherry picked from commit b5a27bd) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 874218f commit c5d3599

6 files changed

Lines changed: 40 additions & 10 deletions

File tree

‎Android/android.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ async def gradle_task(context):
659659
# Randomization is disabled because order-dependent failures are
660660
# much less likely to pass on a rerun in single-process mode.
661661
"-m", "test",
662-
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize"
662+
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize",
663+
"--pythoninfo",
663664
]
664665

665666
if not any(arg in context.args for arg in ["-c", "-m"]):

‎Lib/test/libregrtest/cmdline.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ def _create_parser():
393393
help='remove old test_python_* directories')
394394
group.add_argument('--bisect', action='store_true',
395395
help='if some tests fail, run test.bisect_cmd on them')
396+
group.add_argument('--pythoninfo', action='store_true',
397+
help="run python -m test.pythoninfo before tests")
396398
group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
397399
action='store_false',
398400
help="internal option, don't use it")

‎Lib/test/libregrtest/main.py‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
strip_py_suffix, count, format_duration,
2727
printlist, get_temp_dir, get_work_dir, exit_timeout,
2828
display_header, cleanup_temp_dir, print_warning,
29-
is_cross_compiled, get_host_runner,
29+
is_cross_compiled, get_host_runner, display_title,
3030
EXIT_TIMEOUT)
3131

3232

@@ -126,6 +126,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
126126
self.coverage: bool = ns.trace
127127
self.coverage_dir: StrPath | None = ns.coverdir
128128
self._tmp_dir: StrPath | None = ns.tempdir
129+
self.pythoninfo: bool = ns.pythoninfo
129130

130131
# Randomize
131132
self.randomize: bool = ns.randomize
@@ -322,9 +323,7 @@ def _run_bisect(self, runtests: RunTests, test: str, progress: str) -> bool:
322323
title = f"Bisect {test}"
323324
if progress:
324325
title = f"{title} ({progress})"
325-
print(title)
326-
print("#" * len(title))
327-
print()
326+
display_title(title)
328327

329328
cmd = runtests.create_python_cmd()
330329
cmd.extend([
@@ -345,9 +344,7 @@ def _run_bisect(self, runtests: RunTests, test: str, progress: str) -> bool:
345344
exitcode = proc.returncode
346345

347346
title = f"{title}: exit code {exitcode}"
348-
print(title)
349-
print("#" * len(title))
350-
print(flush=True)
347+
display_title(title)
351348

352349
if exitcode:
353350
print(f"Bisect failed with exit code {exitcode}")
@@ -752,6 +749,15 @@ def tmp_dir(self) -> StrPath:
752749
)
753750
return self._tmp_dir
754751

752+
def run_pythoninfo(self):
753+
from test import pythoninfo
754+
try:
755+
pythoninfo.main()
756+
except SystemExit:
757+
# Ignore non-zero exit code on purpose
758+
pass
759+
print()
760+
755761
def main(self, tests: TestList | None = None) -> NoReturn:
756762
if self.want_add_python_opts:
757763
self._add_python_opts()
@@ -765,6 +771,9 @@ def main(self, tests: TestList | None = None) -> NoReturn:
765771
if self.want_wait:
766772
input("Press any key to continue...")
767773

774+
if self.pythoninfo:
775+
self.run_pythoninfo()
776+
768777
setup_test_dir(self.test_dir)
769778
selected, tests = self.find_tests(tests)
770779

‎Lib/test/libregrtest/utils.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,3 +730,9 @@ def _sanitize_xml_replace(regs):
730730

731731
def sanitize_xml(text: str) -> str:
732732
return ILLEGAL_XML_CHARS_RE.sub(_sanitize_xml_replace, text)
733+
734+
735+
def display_title(title):
736+
print(title)
737+
print("#" * len(title))
738+
print(flush=True)

‎Lib/test/pythoninfo.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,9 +1360,9 @@ def collect_info(info):
13601360

13611361

13621362
def dump_info(info, file=None):
1363-
title = "Python debug information"
1363+
title = "Python build information"
13641364
print(title)
1365-
print("=" * len(title))
1365+
print("#" * len(title))
13661366
print()
13671367

13681368
infos = info.get_infos()

‎Lib/test/test_regrtest.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ def test_single_process(self):
571571
self.assertEqual(regrtest.num_workers, 0)
572572
self.assertTrue(regrtest.single_process)
573573

574+
def test_pythoninfo(self):
575+
ns = self.parse_args([])
576+
self.assertFalse(ns.pythoninfo)
577+
578+
ns = self.parse_args(['--pythoninfo'])
579+
self.assertTrue(ns.pythoninfo)
580+
574581

575582
@dataclasses.dataclass(slots=True)
576583
class Rerun:
@@ -2431,6 +2438,11 @@ def test_pgo_exclude(self):
24312438
self.assertNotIn('test_re', tests)
24322439
self.assertEqual(len(tests), len(pgo_tests) - 1)
24332440

2441+
def test_pythoninfo(self):
2442+
testname = self.create_test()
2443+
output = self.run_tests('--pythoninfo', testname)
2444+
self.assertIn("Python build information", output)
2445+
24342446

24352447
class TestUtils(unittest.TestCase):
24362448
def test_format_duration(self):

0 commit comments

Comments
 (0)