]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-135494: Fix python -m test --pgo -x test_re (#135713) (#135881)
authorVictor Stinner <vstinner@python.org>
Tue, 24 Jun 2025 10:49:31 +0000 (12:49 +0200)
committerGitHub <noreply@github.com>
Tue, 24 Jun 2025 10:49:31 +0000 (10:49 +0000)
gh-135494: Fix python -m test --pgo -x test_re (#135713)

Fix regrtest to support excluding tests from --pgo tests.

(cherry picked from commit 15c6d63fe6fc62c6d78d2fad81965a8e6f7b7b98)

Lib/test/libregrtest/main.py
Lib/test/test_regrtest.py
Misc/NEWS.d/next/Tests/2025-06-19-15-29-38.gh-issue-135494.FVl9a0.rst [new file with mode: 0644]

index 0ef7b99ae320969191d6d607e9033c2725394fdb..2894da7509110cc0883980d082912b113299cb1e 100644 (file)
@@ -186,6 +186,12 @@ class Regrtest:
 
         strip_py_suffix(tests)
 
+        exclude_tests = set()
+        if self.exclude:
+            for arg in self.cmdline_args:
+                exclude_tests.add(arg)
+            self.cmdline_args = []
+
         if self.pgo:
             # add default PGO tests if no tests are specified
             setup_pgo_tests(self.cmdline_args, self.pgo_extended)
@@ -193,17 +199,15 @@ class Regrtest:
         if self.tsan:
             setup_tsan_tests(self.cmdline_args)
 
-        exclude_tests = set()
-        if self.exclude:
-            for arg in self.cmdline_args:
-                exclude_tests.add(arg)
-            self.cmdline_args = []
-
         alltests = findtests(testdir=self.test_dir,
                              exclude=exclude_tests)
 
         if not self.fromfile:
             selected = tests or self.cmdline_args
+            if exclude_tests:
+                # Support "--pgo/--tsan -x test_xxx" command
+                selected = [name for name in selected
+                            if name not in exclude_tests]
             if selected:
                 selected = split_test_packages(selected)
             else:
index 359a661bd4bd0185cad172afa286f0238a5a4414..2c15f37c7c54ded8585005fd1de902a65862e93d 100644 (file)
@@ -2346,6 +2346,17 @@ class ArgsTestCase(BaseTestCase):
         output = self.run_tests('-j1', '-v', testname, env=env, isolated=False)
         check(output)
 
+    def test_pgo_exclude(self):
+        # Get PGO tests
+        output = self.run_tests('--pgo', '--list-tests')
+        pgo_tests = output.strip().split()
+
+        # Exclude test_re
+        output = self.run_tests('--pgo', '--list-tests', '-x', 'test_re')
+        tests = output.strip().split()
+        self.assertNotIn('test_re', tests)
+        self.assertEqual(len(tests), len(pgo_tests) - 1)
+
 
 class TestUtils(unittest.TestCase):
     def test_format_duration(self):
diff --git a/Misc/NEWS.d/next/Tests/2025-06-19-15-29-38.gh-issue-135494.FVl9a0.rst b/Misc/NEWS.d/next/Tests/2025-06-19-15-29-38.gh-issue-135494.FVl9a0.rst
new file mode 100644 (file)
index 0000000..832d1fe
--- /dev/null
@@ -0,0 +1,2 @@
+Fix regrtest to support excluding tests from ``--pgo`` tests. Patch by
+Victor Stinner.