diff --git a/Lib/test/libregrtest/results.py b/Lib/test/libregrtest/results.py index 4096bfc7191b99..eac8f4c40ebca1 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 1116929a502f84..8553b46f10d37e 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 b34f106a83ca85..0b8f7f51395a64 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 e8211526ae847c..cd2cd8a21e8ea7 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):