https://github.com/python/cpython/commit/612f1ec988314bc0bc42a1b908751950331e2ede
commit: 612f1ec988314bc0bc42a1b908751950331e2ede
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-03-13T14:20:33+01:00
summary:

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.

files:
M Lib/test/libregrtest/filter.py
M Lib/test/test_regrtest.py

diff --git a/Lib/test/libregrtest/filter.py b/Lib/test/libregrtest/filter.py
index 817624d79e9263..41372e427ffd03 100644
--- a/Lib/test/libregrtest/filter.py
+++ b/Lib/test/libregrtest/filter.py
@@ -27,6 +27,11 @@ def _is_full_match_test(pattern):
     return ('.' in pattern) and (not re.search(r'[?*\[\]]', pattern))
 
 
+def get_match_tests():
+    global _test_patterns
+    return _test_patterns
+
+
 def set_match_tests(patterns):
     global _test_matchers, _test_patterns
 
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 7e1eaa7d6a515e..903ad50ba088e8 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -27,7 +27,7 @@
 from test.libregrtest import main
 from test.libregrtest import setup
 from test.libregrtest import utils
-from test.libregrtest.filter import set_match_tests, match_test
+from test.libregrtest.filter import get_match_tests, set_match_tests, 
match_test
 from test.libregrtest.result import TestStats
 from test.libregrtest.utils import normalize_test_name
 
@@ -2298,6 +2298,10 @@ def __init__(self, test_id):
             def id(self):
                 return self.test_id
 
+        # Restore patterns once the test completes
+        patterns = get_match_tests()
+        self.addCleanup(set_match_tests, patterns)
+
         test_access = Test('test.test_os.FileTests.test_access')
         test_chdir = Test('test.test_os.Win32ErrorTests.test_chdir')
         test_copy = Test('test.test_shutil.TestCopy.test_copy')

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to