8000 gh-135494: Fix python -m test --pgo -x test_re (#135713) · python/cpython@15c6d63 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 15c6d63

Browse files
authored
gh-135494: Fix python -m test --pgo -x test_re (#135713)
Fix regrtest to support excluding tests from --pgo tests.
1 parent 2060089 commit 15c6d63

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
@@ -190,6 +190,12 @@ def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList
190190

191191
strip_py_suffix(tests)
192192

193+
exclude_tests = set()
194+
if self.exclude:
195+
for arg in self.cmdline_args:
196+
exclude_tests.add(arg)
197+
self.cmdline_args = []
198+
193199
if self.pgo:
194200
# add default PGO tests if no tests are specified
195201
setup_pgo_tests(self.cmdline_args, self.pgo_extended)
@@ -200,17 +206,15 @@ def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList
200206
if self.tsan_parallel:
201207
setup_tsan_parallel_tests(self.cmdline_args)
202208

203-
exclude_tests = set()
204-
if self.exclude:
205-
for arg in self.cmdline_args:
206-
exclude_tests.add(arg)
207-
self.cmdline_args = []
208-
209209
alltests = findtests(testdir=self.test_dir,
210210
exclude=exclude_tests)
211211

212212
if not self.fromfile:
213213
selected = tests or self.cmdline_args
214+
if exclude_tests:
215+
# Support "--pgo/--tsan -x test_xxx" command
216+
selected = [name for name in selected
217+
if name not in exclude_tests]
214218
if selected:
215219
selected = split_test_packages(selected)
216220
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)
0