Skip to content

Commit 1d95ca5

Browse files
committed
gh-146410: Add --pythoninfo option to regrtest
* Android now runs tests with --pythoninfo to dump build information. * Add display_title() function.
1 parent 3364e7e commit 1d95ca5

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

Android/android.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ async def gradle_task(context):
628628
# Randomization is disabled because order-dependent failures are
629629
# much less likely to pass on a rerun in single-process mode.
630630
"-m", "test",
631-
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize"
631+
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize",
632+
"--pythoninfo",
632633
]
633634

634635
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
@@ -746,3 +746,9 @@ def _sanitize_xml_replace(regs):
746746

747747
def sanitize_xml(text: str) -> str:
748748
return ILLEGAL_XML_CHARS_RE.sub(_sanitize_xml_replace, text)
749+
750+
751+
def display_title(title):
752+
print(title)
753+
print("#" * len(title))
754+
print(flush=True)

Lib/test/pythoninfo.py

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

11041104

11051105
def dump_info(info, file=None):
1106-
title = "Python debug information"
1106+
title = "Python build information"
11071107
print(title)
1108-
print("=" * len(title))
1108+
print("#" * len(title))
11091109
print()
11101110

11111111
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:
@@ -2427,6 +2434,11 @@ def test_pgo_exclude(self):
24272434
self.assertNotIn('test_re', tests)
24282435
self.assertEqual(len(tests), len(pgo_tests) - 1)
24292436

2437+
def test_pythoninfo(self):
2438+
testname = self.create_test()
2439+
output = self.run_tests('--pythoninfo', testname)
2440+
self.assertIn("Python build information", output)
2441+
24302442

24312443
class TestUtils(unittest.TestCase):
24322444
def test_format_duration(self):

0 commit comments

Comments
 (0)