14
14
from jinja2 import Environment , FileSystemLoader , StrictUndefined
15
15
from junit_utils import get_property_value , iter_xml_files
16
16
from gh_status import update_pr_comment_text
17
+ from get_test_history import get_test_history
17
18
18
19
19
20
class TestStatus (Enum ):
@@ -38,6 +39,7 @@ class TestResult:
38
39
status : TestStatus
39
40
log_urls : Dict [str , str ]
40
41
elapsed : float
42
+ count_of_passed : int
41
43
42
44
@property
43
45
def status_display (self ):
@@ -97,7 +99,7 @@ def from_junit(cls, testcase):
97
99
elapsed = 0
98
100
print (f"Unable to cast elapsed time for { classname } ::{ name } value={ elapsed !r} " )
99
101
100
- return cls (classname , name , status , log_urls , elapsed )
102
+ return cls (classname , name , status , log_urls , elapsed , 0 )
101
103
102
104
103
105
class TestSummaryLine :
@@ -222,12 +224,13 @@ def render_pm(value, url, diff=None):
222
224
return text
223
225
224
226
225
- def render_testlist_html (rows , fn ):
227
+ def render_testlist_html (rows , fn , build_preset ):
226
228
TEMPLATES_PATH = os .path .join (os .path .dirname (__file__ ), "templates" )
227
229
228
230
env = Environment (loader = FileSystemLoader (TEMPLATES_PATH ), undefined = StrictUndefined )
229
231
230
232
status_test = {}
233
+ last_n_runs = 5
231
234
has_any_log = set ()
232
235
233
236
for t in rows :
@@ -243,8 +246,35 @@ def render_testlist_html(rows, fn):
243
246
# remove status group without tests
244
247
status_order = [s for s in status_order if s in status_test ]
245
248
249
+ # get failed tests
250
+ failed_tests_array = []
251
+ history = {}
252
+ for test in status_test .get (TestStatus .FAIL , []):
253
+ failed_tests_array .append (test .full_name )
254
+
255
+ if failed_tests_array :
256
+ try :
257
+ history = get_test_history (failed_tests_array , last_n_runs , build_preset )
258
+ except Exception as e :
259
+ print (f'Error:{ e } ' )
260
+
261
+ # sorting, at first show tests with passed resuts in history
262
+
263
+ if TestStatus .FAIL in status_test :
264
+ for test in status_test .get (TestStatus .FAIL , []):
265
+ if test .full_name in history :
266
+ test .count_of_passed = history [test .full_name ][
267
+ next (iter (history [test .full_name ]))
268
+ ]["count_of_passed" ]
269
+ else :
270
+ test .count_of_passed = 0
271
+ status_test [TestStatus .FAIL ].sort (key = lambda val : (val .count_of_passed , val .full_name ), reverse = True )
272
+
246
273
content = env .get_template ("summary.html" ).render (
247
- status_order = status_order , tests = status_test , has_any_log = has_any_log
274
+ status_order = status_order ,
275
+ tests = status_test ,
276
+ has_any_log = has_any_log ,
277
+ history = history ,
248
278
)
249
279
250
280
with open (fn , "w" ) as fp :
@@ -267,7 +297,7 @@ def write_summary(summary: TestSummary):
267
297
fp .close ()
268
298
269
299
270
- def gen_summary (public_dir , public_dir_url , paths , is_retry : bool ):
300
+ def gen_summary (public_dir , public_dir_url , paths , is_retry : bool , build_preset ):
271
301
summary = TestSummary (is_retry = is_retry )
272
302
273
303
for title , html_fn , path in paths :
@@ -281,7 +311,7 @@ def gen_summary(public_dir, public_dir_url, paths, is_retry: bool):
281
311
html_fn = os .path .relpath (html_fn , public_dir )
282
312
report_url = f"{ public_dir_url } /{ html_fn } "
283
313
284
- render_testlist_html (summary_line .tests , os .path .join (public_dir , html_fn ))
314
+ render_testlist_html (summary_line .tests , os .path .join (public_dir , html_fn ), build_preset )
285
315
summary_line .add_report (html_fn , report_url )
286
316
summary .add_line (summary_line )
287
317
@@ -349,7 +379,7 @@ def main():
349
379
paths = iter (args .args )
350
380
title_path = list (zip (paths , paths , paths ))
351
381
352
- summary = gen_summary (args .public_dir , args .public_dir_url , title_path , is_retry = bool (args .is_retry ))
382
+ summary = gen_summary (args .public_dir , args .public_dir_url , title_path , is_retry = bool (args .is_retry ), build_preset = args . build_preset )
353
383
write_summary (summary )
354
384
355
385
if summary .is_failed :
0 commit comments