@@ -108,6 +108,9 @@ class TestResult:
108108 # short descriptions of how the test altered the execution environment
109109 env_changed_reasons : list [str ] | None = None
110110
111+ # test file, set once the test module is imported
112+ filename : str | None = None
113+
111114 def is_failed (self , fail_env_changed : bool ) -> bool :
112115 if self .state == State .ENV_CHANGED :
113116 return fail_env_changed
@@ -205,23 +208,24 @@ def format_github_summary(self, expand: bool) -> str:
205208 return "" .join (f"{ block } \n \n " for block in blocks )
206209
207210 def print_github_annotation (self , runtests : RunTests ) -> None :
208- """Print github error annotation line for each failure."""
209- if not (runtests .github_annotations
210- and self .is_failed (runtests .fail_env_changed )):
211+ """Annotate a failed test file without failed test cases."""
212+ if (not runtests .github_annotations
213+ or not self .is_failed (runtests .fail_env_changed )
214+ or self .failed_test_cases ):
211215 return
212- # Convert python import test name to relative file path.
213- # Ex: "test.test_x.test_y" is test_x/test_y.py
214- name = self . test_name . removeprefix ( " test." )
215- path = pathlib . Path ( findtestdir ( runtests . test_dir ), * name . split ( "." ))
216- filename = path . with_suffix ( " .py" )
217- if not filename . exists ():
218- filename = path / "__init__.py"
219- annotations = self . failed_test_cases
220- if not annotations :
221- message = " \n " . join ([ str ( self ), * ( self . env_changed_reasons or ())])
222- annotations = [( self . test_name , message )]
223- for title , message in annotations :
224- print_github_annotation (title , message , str (filename ))
216+ filename = self . filename
217+ if not filename :
218+ # The worker crashed or timed out before reporting the test file:
219+ # convert python import test name to relative file path.
220+ # Ex: "test.test_x.test_y" is test_x/test_y .py
221+ name = self . test_name . removeprefix ( "test." )
222+ path = pathlib . Path ( findtestdir ( runtests . test_dir ),
223+ * name . split ( "." ))
224+ filename = path . with_suffix ( ".py" )
225+ if not filename . exists ():
226+ filename = path / "__init__.py"
227+ message = " \n " . join ([ str ( self ), * ( self . env_changed_reasons or ())])
228+ print_github_annotation (self . test_name , message , str (filename ))
225229
226230 def set_env_changed (self , * reasons ):
227231 if self .state is None or self .state == State .PASSED :
0 commit comments