@@ -148,22 +148,26 @@ def print_warning(msg: str) -> None:
148148 "," : "%2C" })
149149
150150
151- def print_github_annotation (title : str , message : str , filename : str ,
152- file = None ) -> None :
151+ def print_github_annotation (title : str , message : str ,
152+ filename : str | None = None , file = None ) -> None :
153153 """Print a GitHub Actions error annotation.
154154
155155 message is a traceback or a failure description. Only keep the exception
156156 which ends the traceback: the job log has the full traceback. Locate the
157- annotation at the last traceback frame in a test file, if any, or else
158- in filename, the test file.
157+ annotation at the last traceback frame in a test file, or else at the
158+ first frame (the test), or else in filename ( the test file) .
159159 """
160160 message = decolor (message )
161161 line = None
162- # Last traceback frame (' File "filename", line 123') or failed doctest
163- # example (same, but not indented) in a test file
164- if frames := re .findall (r'^ *File "(.*[/\\]test_[^/\\]*\.py)", line (\d+)' ,
165- message , re .MULTILINE ):
166- filename , line = frames [- 1 ]
162+ # Traceback frames (' File "filename", line 123') and failed doctest
163+ # examples (same, but not indented)
164+ if frames := re .findall (r'^ *File "(.*)", line (\d+)' , message ,
165+ re .MULTILINE ):
166+ test_frames = [frame for frame in frames
167+ if os .path .basename (frame [0 ]).startswith ('test_' )]
168+ filename , line = test_frames [- 1 ] if test_frames else frames [0 ]
169+ if not filename :
170+ raise ValueError (f"missing test file of annotation { title !r} " )
167171 # In the job, the stdlib can be outside of the repository checkout
168172 path = pathlib .Path (filename )
169173 stdlib_dir = pathlib .Path (os .__file__ ).parent
0 commit comments