]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109276: regrtest re-runs "env changed" tests (#109831)
authorVictor Stinner <vstinner@python.org>
Mon, 25 Sep 2023 14:21:01 +0000 (16:21 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Sep 2023 14:21:01 +0000 (16:21 +0200)
When a test fails with "env changed" and --rerun option is used, the
test is now re-run in verbose mode in a fresh process.

Lib/test/libregrtest/results.py
Lib/test/test_regrtest.py
Misc/NEWS.d/next/Tests/2023-09-25-14-41-18.gh-issue-109276.uC_cWo.rst [new file with mode: 0644]

index fc4c547b34ac755f17c45be1177945947ceb34b7..1a8619fb62be2a7545e26c001ebe5770f7a06bcd 100644 (file)
@@ -25,7 +25,7 @@ class TestResults:
         self.env_changed: TestList = []
         self.run_no_tests: TestList = []
         self.rerun: TestList = []
-        self.bad_results: list[TestResult] = []
+        self.rerun_results: list[TestResult] = []
 
         self.interrupted: bool = False
         self.test_times: list[tuple[float, TestName]] = []
@@ -87,6 +87,7 @@ class TestResults:
                 self.good.append(test_name)
             case State.ENV_CHANGED:
                 self.env_changed.append(test_name)
+                self.rerun_results.append(result)
             case State.SKIPPED:
                 self.skipped.append(test_name)
             case State.RESOURCE_DENIED:
@@ -98,7 +99,7 @@ class TestResults:
             case _:
                 if result.is_failed(fail_env_changed):
                     self.bad.append(test_name)
-                    self.bad_results.append(result)
+                    self.rerun_results.append(result)
                 else:
                     raise ValueError(f"invalid test state: {result.state!r}")
 
@@ -114,12 +115,12 @@ class TestResults:
             self.add_junit(xml_data)
 
     def need_rerun(self):
-        return bool(self.bad_results)
+        return bool(self.rerun_results)
 
     def prepare_rerun(self) -> tuple[TestTuple, FilterDict]:
         tests: TestList = []
         match_tests_dict = {}
-        for result in self.bad_results:
+        for result in self.rerun_results:
             tests.append(result.test_name)
 
             match_tests = result.get_rerun_match_tests()
@@ -130,7 +131,8 @@ class TestResults:
         # Clear previously failed tests
         self.rerun_bad.extend(self.bad)
         self.bad.clear()
-        self.bad_results.clear()
+        self.env_changed.clear()
+        self.rerun_results.clear()
 
         return (tuple(tests), match_tests_dict)
 
index 4100c98839b55fa4025811ad9049d5f47e72aaa5..4b819cbbb8dfc3ab8daa937dfebfa701673a8911 100644 (file)
@@ -463,7 +463,7 @@ class BaseTestCase(unittest.TestCase):
             randomize = True
 
         rerun_failed = []
-        if rerun is not None:
+        if rerun is not None and not env_changed:
             failed = [rerun.name]
             if not rerun.success:
                 rerun_failed.append(rerun.name)
@@ -591,7 +591,7 @@ class BaseTestCase(unittest.TestCase):
         state = ', '.join(state)
         if rerun is not None:
             new_state = 'SUCCESS' if rerun.success else 'FAILURE'
-            state = 'FAILURE then ' + new_state
+            state = f'{state} then {new_state}'
         self.check_line(output, f'Result: {state}', full=True)
 
     def parse_random_seed(self, output):
@@ -1229,6 +1229,15 @@ class ArgsTestCase(BaseTestCase):
         self.check_executed_tests(output, [testname], env_changed=testname,
                                   fail_env_changed=True, stats=1)
 
+        # rerun
+        output = self.run_tests("--rerun", testname)
+        self.check_executed_tests(output, [testname],
+                                  env_changed=testname,
+                                  rerun=Rerun(testname,
+                                              match=None,
+                                              success=True),
+                                  stats=2)
+
     def test_rerun_fail(self):
         # FAILURE then FAILURE
         code = textwrap.dedent("""
diff --git a/Misc/NEWS.d/next/Tests/2023-09-25-14-41-18.gh-issue-109276.uC_cWo.rst b/Misc/NEWS.d/next/Tests/2023-09-25-14-41-18.gh-issue-109276.uC_cWo.rst
new file mode 100644 (file)
index 0000000..66651cf
--- /dev/null
@@ -0,0 +1,3 @@
+regrtest: When a test fails with "env changed" and the --rerun option is
+used, the test is now re-run in verbose mode in a fresh process. Patch by
+Victor Stinner.