Skip to content

Commit 946c801

Browse files
committed
drop groups, error only on final failure
1 parent ff7b75a commit 946c801

4 files changed

Lines changed: 17 additions & 38 deletions

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .logger import Logger
1717
from .pgo import setup_pgo_tests
1818
from .result import TestResult
19-
from .results import TestResults, EXITCODE_INTERRUPTED
19+
from .results import TestResults, EXITCODE_INTERRUPTED, annotate_github
2020
from .runtests import RunTests, HuntRefleak
2121
from .setup import setup_process, setup_test_dir
2222
from .single import run_single_test, PROGRESS_MIN_TIME
@@ -491,6 +491,10 @@ def write_github_summary(self) -> None:
491491
return
492492
# Tests which failed in the last run (the re-run, if any)
493493
failed = self.results.rerun_results
494+
if not self.results.rerun:
495+
# Failed tests were not re-run (ex: --python): annotate them now
496+
for result in failed:
497+
annotate_github(result)
494498
cases = [(result.errors or []) + (result.failures or [])
495499
for result in failed]
496500
ncase = sum(map(len, cases))

‎Lib/test/libregrtest/results.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
EXITCODE_INTERRUPTED = 130 # 128 + signal.SIGINT=2
2121

2222

23-
def annotate_github(result: TestResult, level: str) -> None:
23+
def annotate_github(result: TestResult) -> None:
2424
cases = (result.errors or []) + (result.failures or [])
2525
for name, traceback in cases:
26-
github_annotation(level, f"{result.test_name}: {name}",
26+
github_annotation("error", f"{result.test_name}: {name}",
2727
decolor(traceback))
2828
if not cases:
2929
message = "\n".join([str(result), *(result.env_changed_reasons or ())])
30-
github_annotation(level, result.test_name, decolor(message))
30+
github_annotation("error", result.test_name, decolor(message))
3131

3232

3333
class TestResults:
@@ -139,10 +139,10 @@ def accumulate_result(self, result: TestResult, runtests: RunTests) -> None:
139139
if result.state == State.WORKER_BUG:
140140
self.worker_bug = True
141141

142-
if (os.environ.get("GITHUB_STEP_SUMMARY")
142+
if (os.environ.get("GITHUB_STEP_SUMMARY") and rerun
143143
and result.is_failed(fail_env_changed)):
144-
# A failure is only an error if it fails again when re-run
145-
annotate_github(result, "error" if rerun else "warning")
144+
# Only annotate tests which fail again when re-run
145+
annotate_github(result)
146146

147147
if result.has_meaningful_duration() and not rerun:
148148
if result.duration is None:

‎Lib/test/libregrtest/run_workers.py‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import threading
1111
import time
1212
import traceback
13-
from _colorize import decolor # type: ignore[import-not-found]
1413
from typing import Any, Literal, TextIO
1514

1615
from test import support
@@ -520,11 +519,6 @@ def __init__(self, num_workers: int, runtests: RunTests,
520519
else:
521520
self.worker_timeout = None
522521
self.workers: list[WorkerThread] = []
523-
# On GitHub Actions, fold the first run's log into groups: ranges of
524-
# passing tests, and one group per failed test. Re-runs aren't folded.
525-
self.github_groups = (not runtests.rerun
526-
and bool(os.environ.get("GITHUB_STEP_SUMMARY")))
527-
self.in_github_group = False
528522

529523
jobs = self.runtests.get_jobs()
530524
if jobs is not None:
@@ -617,16 +611,7 @@ def _process_result(self, item: QueueOutput) -> TestResult:
617611
self.test_index += 1
618612
mp_result = item[1]
619613
result = mp_result.result
620-
failed = result.is_failed(self.runtests.fail_env_changed)
621-
if self.github_groups and failed:
622-
# Keep the failure annotation out of collapsed groups
623-
self.github_group(None)
624614
self.results.accumulate_result(result, self.runtests)
625-
if self.github_groups:
626-
if failed:
627-
self.github_group(decolor(str(result)))
628-
elif not self.in_github_group:
629-
self.github_group(f"Tests from #{self.test_index}")
630615
self.display_result(mp_result)
631616

632617
# Display worker stdout
@@ -639,19 +624,9 @@ def _process_result(self, item: QueueOutput) -> TestResult:
639624
stdout = mp_result.worker_stdout
640625
if stdout:
641626
print(stdout, flush=True)
642-
if self.github_groups and failed:
643-
self.github_group(None)
644627

645628
return result
646629

647-
def github_group(self, title: str | None) -> None:
648-
"""End the current GitHub Actions log group, start a new one if title."""
649-
if self.in_github_group:
650-
print("::endgroup::", flush=True)
651-
self.in_github_group = title is not None
652-
if title is not None:
653-
print(f"::group::{title}", flush=True)
654-
655630
def get_mem_usage(self):
656631
usage = 0
657632
main_mem = get_process_memory_usage(os.getpid())
@@ -684,7 +659,6 @@ def run(self) -> None:
684659
print()
685660
self.results.interrupted = True
686661
finally:
687-
self.github_group(None)
688662
if self.timeout is not None:
689663
faulthandler.cancel_dump_traceback_later()
690664

‎Lib/test/libregrtest/utils.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ def escape_property(text: str) -> str:
154154

155155
props = f"title={escape_property(title)}"
156156
frames = re.findall(r'^ File "(.+)", line (\d+)', message, re.MULTILINE)
157-
# Source checkout which contains Lib/
158-
srcdir = os.path.dirname(os.path.dirname(os.__file__)) + os.sep
159-
if frames and frames[-1][0].startswith(srcdir):
157+
# Map the stdlib directory (Lib/ in a source checkout or an installed
158+
# lib/python3.X/) to Lib/ in the repository
159+
stdlib_dir = os.path.dirname(os.__file__) + os.sep
160+
if frames and frames[-1][0].startswith(stdlib_dir):
160161
filename, line = frames[-1]
161-
filename = filename.removeprefix(srcdir).replace(os.sep, "/")
162-
props = f"file={escape_property(filename)},line={line},{props}"
162+
filename = filename.removeprefix(stdlib_dir).replace(os.sep, "/")
163+
props = f"file=Lib/{escape_property(filename)},line={line},{props}"
163164
print(f"::{level} {props}::{escape(message)}", flush=True)
164165

165166

0 commit comments

Comments
 (0)