Skip to content

Commit d73971f

Browse files
[3.13] gh-146410: Add --pythoninfo option to regrtest (GH-146413) (#159025)
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 15e701a commit d73971f

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
@@ -658,7 +658,8 @@ async def gradle_task(context):
658658
# Randomization is disabled because order-dependent failures are
659659
# much less likely to pass on a rerun in single-process mode.
660660
"-m", "test",
661-
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize"
661+
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize",
662+
"--pythoninfo",
662663
]
663664

664665
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
@@ -370,6 +370,8 @@ def _create_parser():
370370
help='remove old test_python_* directories')
371371
group.add_argument('--bisect', action='store_true',
372372
help='if some tests fail, run test.bisect_cmd on them')
373+
group.add_argument('--pythoninfo', action='store_true',
374+
help="run python -m test.pythoninfo before tests")
373375
group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
374376
action='store_false',
375377
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
@@ -27,7 +27,7 @@
2727
strip_py_suffix, count, format_duration,
2828
printlist, get_temp_dir, get_work_dir, exit_timeout,
2929
display_header, cleanup_temp_dir, print_warning,
30-
is_cross_compiled, get_host_runner,
30+
is_cross_compiled, get_host_runner, display_title,
3131
EXIT_TIMEOUT)
3232

3333

@@ -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
@@ -300,9 +301,7 @@ def _run_bisect(self, runtests: RunTests, test: str, progress: str) -> bool:
300301
title = f"Bisect {test}"
301302
if progress:
302303
title = f"{title} ({progress})"
303-
print(title)
304-
print("#" * len(title))
305-
print()
304+
display_title(title)
306305

307306
cmd = runtests.create_python_cmd()
308307
cmd.extend([
@@ -323,9 +322,7 @@ def _run_bisect(self, runtests: RunTests, test: str, progress: str) -> bool:
323322
exitcode = proc.returncode
324323

325324
title = f"{title}: exit code {exitcode}"
326-
print(title)
327-
print("#" * len(title))
328-
print(flush=True)
325+
display_title(title)
329326

330327
if exitcode:
331328
print(f"Bisect failed with exit code {exitcode}")
@@ -740,6 +737,15 @@ def tmp_dir(self) -> StrPath:
740737
)
741738
return self._tmp_dir
742739

740+
def run_pythoninfo(self):
741+
from test import pythoninfo
742+
try:
743+
pythoninfo.main()
744+
except SystemExit:
745+
# Ignore non-zero exit code on purpose
746+
pass
747+
print()
748+
743749
def main(self, tests: TestList | None = None) -> NoReturn:
744750
if self.want_add_python_opts:
745751
self._add_python_opts()
@@ -753,6 +759,9 @@ def main(self, tests: TestList | None = None) -> NoReturn:
753759
if self.want_wait:
754760
input("Press any key to continue...")
755761

762+
if self.pythoninfo:
763+
self.run_pythoninfo()
764+
756765
setup_test_dir(self.test_dir)
757766
selected, tests = self.find_tests(tests)
758767

‎Lib/test/libregrtest/utils.py‎

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

804804
def sanitize_xml(text: str) -> str:
805805
return ILLEGAL_XML_CHARS_RE.sub(_sanitize_xml_replace, text)
806+
807+
808+
def display_title(title):
809+
print(title)
810+
print("#" * len(title))
811+
print(flush=True)

‎Lib/test/pythoninfo.py‎

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

13591359

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

13661366
infos = info.get_infos()

‎Lib/test/test_regrtest.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ def test_single_process(self):
568568
self.assertEqual(regrtest.num_workers, 0)
569569
self.assertTrue(regrtest.single_process)
570570

571+
def test_pythoninfo(self):
572+
ns = self.parse_args([])
573+
self.assertFalse(ns.pythoninfo)
574+
575+
ns = self.parse_args(['--pythoninfo'])
576+
self.assertTrue(ns.pythoninfo)
577+
571578

572579
@dataclasses.dataclass(slots=True)
573580
class Rerun:
@@ -2432,6 +2439,11 @@ def test_pgo_exclude(self):
24322439
self.assertNotIn('test_re', tests)
24332440
self.assertEqual(len(tests), len(pgo_tests) - 1)
24342441

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

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

0 commit comments

Comments
 (0)