Skip to content

Commit cde47e2

Browse files
[3.11] gh-110918: Fix side effects of regrtest test_match_tests() (GH-116718) (#116727)
gh-110918: Fix side effects of regrtest test_match_tests() (GH-116718) test_match_tests now saves and restores patterns. Add get_match_tests() function to libregrtest.filter. Previously, running test_regrtest multiple times in a row only ran tests once: "./python -m test test_regrtest -R 3:3. (cherry picked from commit 612f1ec) Co-authored-by: Victor Stinner <[email protected]>
1 parent 1117e7d commit cde47e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/test/libregrtest/filter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def _is_full_match_test(pattern):
2727
return ('.' in pattern) and (not re.search(r'[?*\[\]]', pattern))
2828

2929

30+
def get_match_tests():
31+
global _test_patterns
32+
return _test_patterns
33+
34+
3035
def set_match_tests(patterns):
3136
global _test_matchers, _test_patterns
3237

Lib/test/test_regrtest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from test.libregrtest import main
2828
from test.libregrtest import setup
2929
from test.libregrtest import utils
30-
from test.libregrtest.filter import set_match_tests, match_test
30+
from test.libregrtest.filter import get_match_tests, set_match_tests, match_test
3131
from test.libregrtest.result import TestStats
3232
from test.libregrtest.utils import normalize_test_name
3333

@@ -2234,6 +2234,10 @@ def __init__(self, test_id):
22342234
def id(self):
22352235
return self.test_id
22362236

2237+
# Restore patterns once the test completes
2238+
patterns = get_match_tests()
2239+
self.addCleanup(set_match_tests, patterns)
2240+
22372241
test_access = Test('test.test_os.FileTests.test_access')
22382242
test_chdir = Test('test.test_os.Win32ErrorTests.test_chdir')
22392243
test_copy = Test('test.test_shutil.TestCopy.test_copy')

0 commit comments

Comments
 (0)