@@ -285,8 +285,7 @@ def _rerun_failed_tests(self, runtests: RunTests) -> RunTests:
285285 forever = False ,
286286 fail_fast = False ,
287287 match_tests_dict = match_tests_dict ,
288- output_on_failure = False ,
289- github_annotations = bool (os .environ .get ("GITHUB_STEP_SUMMARY" )))
288+ output_on_failure = False )
290289 self .logger .set_tests (runtests )
291290
292291 msg = f"Re-running { len (tests )} failed tests in verbose mode"
@@ -397,8 +396,7 @@ def run_test(
397396 result = run_single_test (test_name , runtests )
398397
399398 self .results .accumulate_result (result , runtests )
400- if runtests .github_annotations :
401- result .print_github_annotation (runtests )
399+ result .print_github_annotation (runtests )
402400
403401 return result
404402
@@ -540,13 +538,6 @@ def display_summary(self) -> None:
540538 print (f"Result: { state } " )
541539
542540 def create_run_tests (self , tests : TestTuple ) -> RunTests :
543- # Annotate test failures in the GitHub Actions job log of the last
544- # run (the re-run, if any), if it reports failures: -v, -W or --pgo
545- will_rerun = self .want_rerun and not self .python_cmd
546- github_annotations = (bool (os .environ .get ("GITHUB_STEP_SUMMARY" ))
547- and not will_rerun
548- and bool (self .verbose or self .output_on_failure
549- or self .pgo ))
550541 return RunTests (
551542 tests ,
552543 fail_fast = self .fail_fast ,
@@ -564,7 +555,6 @@ def create_run_tests(self, tests: TestTuple) -> RunTests:
564555 hunt_refleak = self .hunt_refleak ,
565556 test_dir = self .test_dir ,
566557 use_junit = (self .junit_filename is not None ),
567- github_annotations = github_annotations ,
568558 coverage = self .coverage ,
569559 memory_limit = self .memory_limit ,
570560 gc_threshold = self .gc_threshold ,
@@ -627,10 +617,16 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
627617 if use_load_tracker :
628618 self .logger .start_load_tracker ()
629619 try :
630- if self .num_workers :
631- self ._run_tests_mp (runtests , self .num_workers )
632- else :
633- self .run_tests_sequentially (runtests )
620+ with os_helper .EnvironmentVarGuard () as env :
621+ # In GitHub Actions, only annotate failures of the last run:
622+ # not the first run if failed tests will be re-run (with
623+ # --python, they are not: see rerun_failed_tests())
624+ if self .want_rerun and not self .python_cmd :
625+ env .unset ("GITHUB_STEP_SUMMARY" )
626+ if self .num_workers :
627+ self ._run_tests_mp (runtests , self .num_workers )
628+ else :
629+ self .run_tests_sequentially (runtests )
634630
635631 coverage = self .results .get_coverage_results ()
636632 self .display_result (runtests )
0 commit comments