Skip to content

Commit 87ddb95

Browse files
committed
gh-161430: Cleanup tests name in regrtest TestResults.display_result() (#161567)
Add utils.cleanup_test_name() function. (cherry picked from commit d7684fb)
1 parent dcc87b9 commit 87ddb95

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎Lib/test/libregrtest/results.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .skipped import expected_to_be_skipped
99
from .utils import (
1010
StrPath, TestName, TestTuple, TestList, FilterDict,
11-
printlist, count, format_duration)
11+
printlist, count, format_duration, cleanup_test_name)
1212

1313
if TYPE_CHECKING:
1414
from xml.etree.ElementTree import Element
@@ -101,9 +101,7 @@ def get_exitcode(self, fail_env_changed: bool, fail_rerun: bool) -> int:
101101
return exitcode
102102

103103
def accumulate_result(self, result: TestResult, runtests: RunTests) -> None:
104-
test_name = result.test_name
105-
# Remove "test." prefix added by some test packages
106-
test_name = test_name.removeprefix('test.')
104+
test_name = cleanup_test_name(result.test_name)
107105
rerun = runtests.rerun
108106
fail_env_changed = runtests.fail_env_changed
109107

@@ -221,6 +219,8 @@ def split_expected_skip(self, tests):
221219
return (skipped, expected)
222220

223221
def display_result(self, tests: TestTuple, quiet: bool, print_slowest: bool) -> None:
222+
tests = tuple(cleanup_test_name(name) for name in tests)
223+
224224
ansi = get_colors()
225225
green = ansi.GREEN
226226
red = ansi.BOLD_RED

‎Lib/test/libregrtest/skipped.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import sysconfig
99
from test import support
10+
from .utils import cleanup_test_name
1011

1112

1213
# On a WASI CI, the main regrtest process is run on the build Python and test
@@ -295,7 +296,7 @@
295296

296297
def expected_to_be_skipped(test_name):
297298
# Test EXPECTED_SKIP
298-
test_name = test_name.removeprefix('test.')
299+
test_name = cleanup_test_name(test_name)
299300
if test_name in EXPECTED_SKIP:
300301
return True
301302
package = test_name.split('.')[0]

‎Lib/test/libregrtest/utils.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
FilterDict = dict[TestName, FilterTuple]
5858

5959

60+
def cleanup_test_name(name: TestName) -> TestName:
61+
return name.removeprefix('test.')
62+
63+
6064
def format_duration(seconds: float) -> str:
6165
ms = math.ceil(seconds * 1e3)
6266
seconds, ms = divmod(ms, 1000)

‎Lib/test/test_regrtest.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,21 @@ def test_sanitize_xml(self):
26772677
self.assertEqual(sanitize_xml('valid t\xe9xt \u20ac'),
26782678
'valid t\xe9xt \u20ac')
26792679

2680+
def test_cleanup_test_name(self):
2681+
cleanup_test_name = utils.cleanup_test_name
2682+
2683+
# Strip "test." prefix
2684+
self.assertEqual(cleanup_test_name('test.test_asyncio.test_graph'),
2685+
'test_asyncio.test_graph')
2686+
self.assertEqual(cleanup_test_name('test.test_multiprocessing_spawn.test_manager'),
2687+
'test_multiprocessing_spawn.test_manager')
2688+
2689+
# No change
2690+
self.assertEqual(cleanup_test_name('test_cmath'),
2691+
'test_cmath')
2692+
self.assertEqual(cleanup_test_name('test_asyncio.test_graph'),
2693+
'test_asyncio.test_graph')
2694+
26802695

26812696
from test.libregrtest.results import TestResults
26822697

0 commit comments

Comments
 (0)