Skip to content

Commit 287df00

Browse files
committed
Remove redundant printing
1 parent 1222c34 commit 287df00

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎Lib/test/libregrtest/testresult.py‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,13 @@ def printErrorList(self, flavour, errors):
135135
if not self.GITHUB_ANNOTATIONS:
136136
super().printErrorList(flavour, errors)
137137
return
138-
stream = self.stream
139138
for test, err in errors:
140-
# Precede each failure report with a GitHub Actions annotation
141-
# which has the report as message, so that the annotation links
142-
# to the report in the job log.
143-
self.stream = unittest.runner._WritelnDecorator(io.StringIO())
144-
try:
145-
super().printErrorList(flavour, [(test, err)])
146-
report = self.stream.getvalue()
147-
finally:
148-
self.stream = stream
149-
stream.writeln(github_annotation(str(test), report))
150-
stream.write(report)
151-
stream.flush()
139+
# Precede each failure report with a GitHub Actions annotation,
140+
# so that the annotation links to the report in the job log. The
141+
# report follows: don't repeat it in the annotation.
142+
self.stream.writeln(github_annotation(str(test), err,
143+
include_message=False))
144+
super().printErrorList(flavour, [(test, err)])
152145

153146
def get_xml_element(self):
154147
if not self.USE_XML:

‎Lib/test/libregrtest/utils.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ def traceback_location(traceback: str) -> dict[str, str | int] | None:
175175
return location
176176

177177

178-
def github_annotation(title: str, message: str) -> str:
178+
def github_annotation(title: str, message: str, *,
179+
include_message: bool = True) -> str:
179180
"""Format a GitHub Actions error annotation.
180181
181-
Locate it at the last frame of the traceback in message, if any.
182+
Locate it at the last frame of the traceback in message, if any. If
183+
include_message is false, the annotation only has the location and the
184+
title.
182185
"""
183186
def escape(text: str) -> str:
184187
return (text.replace("%", "%25").replace("\r", "%0D")
@@ -199,7 +202,7 @@ def escape_property(text: str) -> str:
199202
props["title"] = title
200203
# The job log only shows the message, not the properties: start the
201204
# message with the location and the title
202-
message = f"{header}\n{message}"
205+
message = f"{header}\n{message}" if include_message else header
203206
props_text = ",".join(f"{key}={escape_property(str(value))}"
204207
for key, value in props.items())
205208
return f"::error {props_text}::{escape(message)}"

0 commit comments

Comments
 (0)