Skip to content

Commit 53024ed

Browse files
committed
Remove special summary case, more full output everywhere
1 parent 287df00 commit 53024ed

3 files changed

Lines changed: 14 additions & 30 deletions

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def _rerun_failed_tests(self, runtests: RunTests) -> RunTests:
285285
fail_fast=False,
286286
match_tests_dict=match_tests_dict,
287287
output_on_failure=False,
288-
# Annotate tests which fail again
289288
github_annotations=bool(os.environ.get("GITHUB_STEP_SUMMARY")))
290289
self.logger.set_tests(runtests)
291290

@@ -495,11 +494,6 @@ def write_github_summary(self) -> None:
495494
return
496495
# Tests which failed in the last run (the re-run, if any)
497496
failed = self.results.rerun_results
498-
if not self.results.rerun:
499-
# Failed tests were not re-run (ex: --python): annotate them now.
500-
# Otherwise, they were annotated when they failed again.
501-
for result in failed:
502-
result.print_github_annotations()
503497
cases = [(result.errors or []) + (result.failures or [])
504498
for result in failed]
505499
ncase = sum(map(len, cases))
@@ -561,7 +555,10 @@ def create_run_tests(self, tests: TestTuple) -> RunTests:
561555
hunt_refleak=self.hunt_refleak,
562556
test_dir=self.test_dir,
563557
use_junit=(self.junit_filename is not None),
564-
github_annotations=False,
558+
# Only annotate failures of the last run: the re-run, if any
559+
github_annotations=(bool(os.environ.get("GITHUB_STEP_SUMMARY"))
560+
and not (self.want_rerun
561+
and not self.python_cmd)),
565562
coverage=self.coverage,
566563
memory_limit=self.memory_limit,
567564
gc_threshold=self.gc_threshold,

‎Lib/test/libregrtest/result.py‎

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import dataclasses
22
import json
3-
import os
43
from _colorize import get_colors # type: ignore[import-not-found]
54
from typing import Any
65

@@ -179,34 +178,17 @@ def __str__(self) -> str:
179178
def has_meaningful_duration(self):
180179
return State.has_meaningful_duration(self.state)
181180

182-
def get_github_annotations(self) -> list[tuple[str, str]]:
183-
"""(test case name, message) of each failed test case.
184-
185-
Without test case details (crash, timeout, env changed, etc.), return
186-
the test name and the test result.
187-
"""
188-
if not os.environ.get("GITHUB_STEP_SUMMARY"):
189-
return []
190-
annotations = (self.errors or []) + (self.failures or [])
191-
if not annotations:
192-
message = "\n".join([str(self), *(self.env_changed_reasons or ())])
193-
annotations = [(self.test_name, message)]
194-
return annotations
195-
196-
def print_github_annotations(self) -> None:
197-
"""Print a GitHub Actions error annotation per failed test case."""
198-
for title, message in self.get_github_annotations():
199-
print(github_annotation(title, message), flush=True)
200-
201181
def print_github_crash_annotation(self, fail_env_changed: bool) -> None:
202182
"""Annotate a failed test without test case failures.
203183
204-
Test case failures are annotated by the test runner, where they are
205-
reported (see RegressionTestResult.printErrorList()).
184+
For example: crash, timeout, env changed. Test case failures are
185+
annotated by the test runner, where they are reported (see
186+
RegressionTestResult.printErrorList()).
206187
"""
207188
if (self.is_failed(fail_env_changed)
208189
and not self.errors and not self.failures):
209-
self.print_github_annotations()
190+
message = "\n".join([str(self), *(self.env_changed_reasons or ())])
191+
print(github_annotation(self.test_name, message), flush=True)
210192

211193
def set_env_changed(self, *reasons):
212194
if self.state is None or self.state == State.PASSED:

‎Lib/test/libregrtest/testresult.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ def get_xml_element(self):
154154

155155
class QuietRegressionTestRunner:
156156
def __init__(self, stream, buffer=False):
157+
# Wrap the stream as TextTestRunner does, for printErrors()
158+
stream = unittest.runner._WritelnDecorator(stream)
157159
self.result = RegressionTestResult(stream, None, 0)
158160
self.result.buffer = buffer
159161

160162
def run(self, test):
161163
test(self.result)
164+
if self.result.GITHUB_ANNOTATIONS:
165+
# Report annotated failures, as in verbose mode
166+
self.result.printErrors()
162167
return self.result
163168

164169
def get_test_runner_class(verbosity, buffer=False):

0 commit comments

Comments
 (0)