Skip to content

Commit a27398d

Browse files
authored
[3.13] pythongh-135494: Fix python -m test --pgo -x test_re (python#135713) (python#135881)
pythongh-135494: Fix python -m test --pgo -x test_re (python#135713) Fix regrtest to support excluding tests from --pgo tests. (cherry picked from commit 15c6d63)
1 parent 028d56f commit a27398d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

Lib/test/libregrtest/main.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,28 @@ def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList
186186

187187
strip_py_suffix(tests)
188188

189+
exclude_tests = set()
190+
if self.exclude:
191+
for arg in self.cmdline_args:
192+
exclude_tests.add(arg)
193+
self.cmdline_args = []
194+
189195
if self.pgo:
190196
# add default PGO tests if no tests are specified
191197
setup_pgo_tests(self.cmdline_args, self.pgo_extended)
192198

193199
if self.tsan:
194200
setup_tsan_tests(self.cmdline_args)
195201

196-
exclude_tests = set()
197-
if self.exclude:
198-
for arg in self.cmdline_args:
199-
exclude_tests.add(arg)
200-
self.cmdline_args = []
201-
202202
alltests = findtests(testdir=self.test_dir,
203203
exclude=exclude_tests)
204204

205205
if not self.fromfile:
206206
selected = tests or self.cmdline_args
207+
if exclude_tests:
208+
# Support "--pgo/--tsan -x test_xxx" command
209+
selected = [name for name in selected
210+
if name not in exclude_tests]
207211
if selected:
208212
selected = split_test_packages(selected)
209213
else:

Lib/test/test_regrtest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,17 @@ def check(output):
23462346
output = self.run_tests('-j1', '-v', testname, env=env, isolated=False)
23472347
check(output)
23482348

2349+
def test_pgo_exclude(self):
2350+
# Get PGO tests
2351+
output = self.run_tests('--pgo', '--list-tests')
2352+
pgo_tests = output.strip().split()
2353+
2354+
# Exclude test_re
2355+
output = self.run_tests('--pgo', '--list-tests', '-x', 'test_re')
2356+
tests = output.strip().split()
2357+
self.assertNotIn('test_re', tests)
2358+
self.assertEqual(len(tests), len(pgo_tests) - 1)
2359+
23492360

23502361
class TestUtils(unittest.TestCase):
23512362
def test_format_duration(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix regrtest to support excluding tests from ``--pgo`` tests. Patch by
2+
Victor Stinner.

0 commit comments

Comments
 (0)