8000 gh-109276: regrtest re-runs "env changed" tests by vstinner · Pull Request #109831 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-109276: regrtest re-runs "env changed" tests #109831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Lib/test/libregrtest/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self):
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]] = []
Expand Down Expand Up @@ -82,6 +82,7 @@ def accumulate_result(self, result: TestResult, runtests: RunTests):
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:
Expand All @@ -93,7 +94,7 @@ def accumulate_result(self, result: TestResult, runtests: RunTests):
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}")

Expand All @@ -109,12 +110,12 @@ def accumulate_result(self, result: TestResult, runtests: RunTests):
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()
Expand All @@ -125,7 +126,8 @@ def prepare_rerun(self) -> tuple[TestTuple, FilterDict]:
# 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)

Expand Down
13 changes: 11 additions & 2 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def check_executed_tests(self, output, tests, *, stats,
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)
Expand Down Expand Up @@ -590,7 +590,7 @@ def list_regex(line_format, tests):
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):
Expand Down Expand Up @@ -1228,6 +1228,15 @@ def test_env_changed(self):
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("""
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
0