gh-135494: Fix python -m test --pgo -x test_re (#135713)

Fix regrtest to support excluding tests from --pgo tests.
This commit is contained in:
Victor Stinner 2025-06-24 12:21:35 +02:00 committed by GitHub
parent 2060089254
commit 15c6d63fe6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View file

@ -190,6 +190,12 @@ class Regrtest:
strip_py_suffix(tests)
exclude_tests = set()
if self.exclude:
for arg in self.cmdline_args:
exclude_tests.add(arg)
self.cmdline_args = []
if self.pgo:
# add default PGO tests if no tests are specified
setup_pgo_tests(self.cmdline_args, self.pgo_extended)
@ -200,17 +206,15 @@ class Regrtest:
if self.tsan_parallel:
setup_tsan_parallel_tests(self.cmdline_args)
exclude_tests = set()
if self.exclude:
for arg in self.cmdline_args:
exclude_tests.add(arg)
self.cmdline_args = []
alltests = findtests(testdir=self.test_dir,
exclude=exclude_tests)
if not self.fromfile:
selected = tests or self.cmdline_args
if exclude_tests:
# Support "--pgo/--tsan -x test_xxx" command
selected = [name for name in selected
if name not in exclude_tests]
if selected:
selected = split_test_packages(selected)
else:

View file

@ -2346,6 +2346,17 @@ class ArgsTestCase(BaseTestCase):
output = self.run_tests('-j1', '-v', testname, env=env, isolated=False)
check(output)
def test_pgo_exclude(self):
# Get PGO tests
output = self.run_tests('--pgo', '--list-tests')
pgo_tests = output.strip().split()
# Exclude test_re
output = self.run_tests('--pgo', '--list-tests', '-x', 'test_re')
tests = output.strip().split()
self.assertNotIn('test_re', tests)
self.assertEqual(len(tests), len(pgo_tests) - 1)
class TestUtils(unittest.TestCase):
def test_format_duration(self):

View file

@ -0,0 +1,2 @@
Fix regrtest to support excluding tests from ``--pgo`` tests. Patch by
Victor Stinner.