Skip to content

Commit 3eeb4db

Browse files
committed
gh-158895: Teach librertest to output github job summaries
Goal is to make it faster to triage individual test failures while keeping the full existing regrtest fidelity. Fairly minimal integration to hopefully save some human eyeball time. Setup so only the test summary process should output the summary, subprocesses have the env var which will cause output unset.
1 parent 85c03d4 commit 3eeb4db

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
import io
13
import os
24
import random
35
import re
@@ -6,7 +8,7 @@
68
import sysconfig
79
import time
810
import trace
9-
from _colorize import get_colors # type: ignore[import-not-found]
11+
from _colorize import decolor, get_colors # type: ignore[import-not-found]
1012
from typing import NoReturn
1113

1214
from test.support import os_helper, MS_WINDOWS, flush_std_streams
@@ -480,6 +482,25 @@ def finalize_tests(self, coverage: trace.CoverageResults | None) -> None:
480482
if self.junit_filename:
481483
self.results.write_junit(self.junit_filename)
482484

485+
self.write_github_summary()
486+
487+
def write_github_summary(self) -> None:
488+
filename = os.environ.get("GITHUB_STEP_SUMMARY")
489+
if not filename:
490+
return
491+
with contextlib.redirect_stdout(io.StringIO()) as summary:
492+
self.display_summary()
493+
lines = ["## Test results",
494+
f"```\n{decolor(summary.getvalue()).strip()}\n```"]
495+
# Tests which failed in the last run (the re-run, if any)
496+
for result in self.results.rerun_results:
497+
lines.append(f"### {decolor(str(result))}")
498+
for name, traceback in (result.errors or []) + (result.failures or []):
499+
lines.append(f"<details><summary>{name}</summary>\n\n"
500+
f"```\n{traceback}\n```\n</details>")
501+
with open(filename, "a", encoding="utf-8") as fp:
502+
fp.write("\n\n".join(lines) + "\n")
503+
483504
def display_summary(self) -> None:
484505
if self.first_runtests is None:
485506
raise ValueError(

‎Lib/test/libregrtest/worker.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def create_worker_process(runtests: WorkerRunTests, output_fd: int,
2828
cmd.extend(['-m', 'test.libregrtest.worker', worker_json])
2929

3030
env = dict(os.environ)
31+
# Only the main process writes the GitHub Actions job summary
32+
env.pop('GITHUB_STEP_SUMMARY', None)
3133
if tmp_dir is not None:
3234
env['TMPDIR'] = tmp_dir
3335
env['TEMP'] = tmp_dir
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Individual test failures and an overall summary is now written by
2+
:mod:`test.regrtest` to the Github Action Summary.

0 commit comments

Comments
 (0)