@@ -184,8 +184,7 @@ def has_meaningful_duration(self):
184184 return State .has_meaningful_duration (self .state )
185185
186186 @property
187- def test_cases (self ) -> list [tuple [str , str ]]:
188- """Failed test cases: list of (name, traceback)."""
187+ def failed_test_cases (self ) -> list [tuple [str , str ]]:
189188 return (self .errors or []) + (self .failures or [])
190189
191190 def format_github_summary (self , expand : bool ) -> str :
@@ -194,37 +193,34 @@ def format_github_summary(self, expand: bool) -> str:
194193 if self .env_changed_reasons :
195194 blocks .append ("\n " .join (f"- { reason } "
196195 for reason in self .env_changed_reasons ))
197- for name , traceback in self .test_cases :
198- # Expand the tracebacks if they fit on a screen: a traceback of
199- # less than 30 lines
196+ for name , traceback in self .failed_test_cases :
197+ # Only default open short tracebacks.
200198 is_open = expand and traceback .count ("\n " ) < 30
201199 blocks += [f"<details{ ' open' if is_open else '' } >"
202200 f"<summary>{ html .escape (name )} </summary>" ,
203201 f"```pytb\n { decolor (traceback ).rstrip ()} \n ```" ,
204202 "</details>" ]
203+
205204 # Separate Markdown blocks with an empty line
206205 return "" .join (f"{ block } \n \n " for block in blocks )
207206
208207 def print_github_annotation (self , runtests : RunTests ) -> None :
209- """Annotate each failed test case, or else the failed test file.
210-
211- For example, the test file for a crash, timeout or env changed.
212- """
208+ """Print github error annotation line for each failure."""
213209 if not (runtests .github_annotations
214210 and self .is_failed (runtests .fail_env_changed )):
215211 return
216- # Test file: "test_x" is test_x.py or test_x/__init__.py,
217- # "test.test_x.test_y" is test_x/test_y.py
212+ # Convert python import test name to relative file path.
213+ # Ex: "test.test_x.test_y" is test_x/test_y.py
218214 name = self .test_name .removeprefix ("test." )
219215 path = pathlib .Path (findtestdir (runtests .test_dir ), * name .split ("." ))
220216 filename = path .with_suffix (".py" )
221217 if not filename .exists ():
222218 filename = path / "__init__.py"
223- test_cases = self .test_cases
224- if not test_cases :
219+ annotations = self .failed_test_cases
220+ if not annotations :
225221 message = "\n " .join ([str (self ), * (self .env_changed_reasons or ())])
226- test_cases = [(self .test_name , message )]
227- for title , message in test_cases :
222+ annotations = [(self .test_name , message )]
223+ for title , message in annotations :
228224 print_github_annotation (title , message , str (filename ))
229225
230226 def set_env_changed (self , * reasons ):
0 commit comments