From 08a113266ab52af5c8ddd8407128c9bd7a12da68 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 7 Nov 2026 17:42:04 +0100 Subject: [PATCH] gh-161430: Cleanup tests name in regrtest TestResults.display_result() Add utils.cleanup_test_name() function. --- Lib/test/libregrtest/results.py | 8 ++++---- Lib/test/libregrtest/skipped.py | 3 ++- Lib/test/libregrtest/utils.py | 4 ++++ Lib/test/test_regrtest.py | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Lib/test/libregrtest/results.py b/Lib/test/libregrtest/results.py index 4096bfc7191b99b..eac8f4c40ebca17 100644 --- a/Lib/test/libregrtest/results.py +++ b/Lib/test/libregrtest/results.py @@ -8,7 +8,7 @@ from .skipped import expected_to_be_skipped from .utils import ( StrPath, TestName, TestTuple, TestList, FilterDict, - printlist, count, format_duration) + printlist, count, format_duration, cleanup_test_name) # Python uses exit code 1 when an exception is not caught @@ -98,9 +98,7 @@ def get_exitcode(self, fail_env_changed: bool, fail_rerun: bool) -> int: return exitcode def accumulate_result(self, result: TestResult, runtests: RunTests) -> None: - test_name = result.test_name - # Remove "test." prefix added by some test packages - test_name = test_name.removeprefix('test.') + test_name = cleanup_test_name(result.test_name) rerun = runtests.rerun fail_env_changed = runtests.fail_env_changed @@ -218,6 +216,8 @@ def split_expected_skip(self, tests): return (skipped, expected) def display_result(self, tests: TestTuple, quiet: bool, print_slowest: bool) -> None: + tests = tuple(cleanup_test_name(name) for name in tests) + ansi = get_colors() green = ansi.GREEN red = ansi.BOLD_RED diff --git a/Lib/test/libregrtest/skipped.py b/Lib/test/libregrtest/skipped.py index 1116929a502f84f..8553b46f10d37e1 100644 --- a/Lib/test/libregrtest/skipped.py +++ b/Lib/test/libregrtest/skipped.py @@ -7,6 +7,7 @@ import sys import sysconfig from test import support +from .utils import cleanup_test_name # On a WASI CI, the main regrtest process is run on the build Python and test @@ -295,7 +296,7 @@ def expected_to_be_skipped(test_name): # Test EXPECTED_SKIP - test_name = test_name.removeprefix('test.') + test_name = cleanup_test_name(test_name) if test_name in EXPECTED_SKIP: return True package = test_name.split('.')[0] diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index b34f106a83ca854..0b8f7f51395a643 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -67,6 +67,10 @@ FilterDict = dict[TestName, FilterTuple] +def cleanup_test_name(name: TestName) -> TestName: + return name.removeprefix('test.') + + def format_duration(seconds: float) -> str: ms = math.ceil(seconds * 1e3) seconds, ms = divmod(ms, 1000) diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index e8211526ae847c5..cd2cd8a21e8ea7f 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -2981,6 +2981,21 @@ def test_sanitize_xml(self): self.assertEqual(sanitize_xml('valid t\xe9xt \u20ac'), 'valid t\xe9xt \u20ac') + def test_cleanup_test_name(self): + cleanup_test_name = utils.cleanup_test_name + + # Strip "test." prefix + self.assertEqual(cleanup_test_name('test.test_asyncio.test_graph'), + 'test_asyncio.test_graph') + self.assertEqual(cleanup_test_name('test.test_multiprocessing_spawn.test_manager'), + 'test_multiprocessing_spawn.test_manager') + + # No change + self.assertEqual(cleanup_test_name('test_cmath'), + 'test_cmath') + self.assertEqual(cleanup_test_name('test_asyncio.test_graph'), + 'test_asyncio.test_graph') + class GitHubActionsReporterTestCase(unittest.TestCase): def setUp(self):