@@ -98,6 +98,23 @@ def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
9898 )
9999 return output
100100
101+ def get_failures (junit_objects ) -> dict [str , list [tuple [str , str ]]]:
102+ failures = {}
103+ for results in junit_objects :
104+ for testsuite in results :
105+ for test in testsuite :
106+ if (
107+ not test .is_passed
108+ and test .result
109+ and isinstance (test .result [0 ], Failure )
110+ ):
111+ if failures .get (testsuite .name ) is None :
112+ failures [testsuite .name ] = []
113+ failures [testsuite .name ].append (
114+ (test .classname + "/" + test .name , test .result [0 ].text )
115+ )
116+ return failures
117+
101118
102119# Set size_limit to limit the byte size of the report. The default is 1MB as this
103120# is the most that can be put into an annotation. If the generated report exceeds
@@ -113,7 +130,7 @@ def generate_report(
113130 size_limit = 1024 * 1024 ,
114131 list_failures = True ,
115132):
116- failures = {}
133+ failures = get_failures ( junit_objects )
117134 tests_run = 0
118135 tests_skipped = 0
119136 tests_failed = 0
@@ -124,18 +141,6 @@ def generate_report(
124141 tests_skipped += testsuite .skipped
125142 tests_failed += testsuite .failures
126143
127- for test in testsuite :
128- if (
129- not test .is_passed
130- and test .result
131- and isinstance (test .result [0 ], Failure )
132- ):
133- if failures .get (testsuite .name ) is None :
134- failures [testsuite .name ] = []
135- failures [testsuite .name ].append (
136- (test .classname + "/" + test .name , test .result [0 ].text )
137- )
138-
139144 report = [f"# { title } " , "" ]
140145
141146 if tests_run == 0 :
@@ -258,7 +263,7 @@ def plural(num_tests):
258263 return report
259264
260265
261- def generate_report_from_files ( title , return_code , build_log_files ):
266+ def load_info_from_files ( build_log_files ):
262267 junit_files = [
263268 junit_file for junit_file in build_log_files if junit_file .endswith (".xml" )
264269 ]
@@ -271,6 +276,11 @@ def generate_report_from_files(title, return_code, build_log_files):
271276 ninja_logs .append (
272277 [log_line .strip () for log_line in ninja_log_file_handle .readlines ()]
273278 )
279+ return [JUnitXml .fromfile (p ) for p in junit_files ], ninja_logs
280+
281+
282+ def generate_report_from_files (title , return_code , build_log_files ):
283+ junit_objects , ninja_logs = load_info_from_files (build_log_files )
274284 return generate_report (
275- title , return_code , [ JUnitXml . fromfile ( p ) for p in junit_files ] , ninja_logs
285+ title , return_code , junit_objects , ninja_logs
276286 )
0 commit comments