Skip to content

Commit 612f1ec

Browse files
authored
gh-110918: Fix side effects of regrtest test_match_tests() (#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.
1 parent 33662d4 commit 612f1ec

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

@@ -2298,6 +2298,10 @@ def __init__(self, test_id):
22982298
def id(self):
22992299
return self.test_id
23002300

2301+
# Restore patterns once the test completes
2302+
patterns = get_match_tests()
2303+
self.addCleanup(set_match_tests, patterns)
2304+
23012305
test_access = Test('test.test_os.FileTests.test_access')
23022306
test_chdir = Test('test.test_os.Win32ErrorTests.test_chdir')
23032307
test_copy = Test('test.test_shutil.TestCopy.test_copy')

0 commit comments

Comments
 (0)