@@ -246,21 +246,33 @@ def mark_results(testrail_session: TestRail, test_results):
246
246
for result in existing_results [run_id ]
247
247
}
248
248
suite_id = test_results [category ][run_id ][0 ].get ("suite_id" )
249
- all_test_cases = [
250
- result .get ("test_case" ) for result in test_results [category ][run_id ]
251
- ]
249
+
250
+ all_test_cases = []
251
+ all_durations = []
252
+ for result in test_results [category ][run_id ]:
253
+ all_test_cases .append (result .get ("test_case" ))
254
+ all_durations .append (result .get ("duration" ))
252
255
253
256
# Don't set passed tests to another status.
254
- test_cases = [tc for tc in all_test_cases if current_results .get (tc ) != 1 ]
257
+ test_cases_ids = []
258
+ durations = []
259
+ for i , test_case in enumerate (all_test_cases ):
260
+ if current_results .get (test_case ) != 1 :
261
+ test_cases_ids .append (test_case )
262
+ durations .append (all_durations [i ])
263
+ logging .warning (
264
+ f"Setting the following test cases in run { run_id } to { category } : { test_cases_ids } "
265
+ )
255
266
logging .warning (
256
- f"Setting the following test cases in run { run_id } to { category } : { test_cases } "
267
+ f"Setting the following test cases { test_cases_ids } to duration { durations } "
257
268
)
258
269
testrail_session .update_test_cases (
259
270
test_results .get ("project_id" ),
260
271
testrail_run_id = run_id ,
261
272
testrail_suite_id = suite_id ,
262
- test_case_ids = test_cases ,
273
+ test_case_ids = test_cases_ids ,
263
274
status = category ,
275
+ elapsed = durations ,
264
276
)
265
277
266
278
@@ -407,6 +419,7 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
407
419
cases_in_suite = suite_info .get ("cases" )
408
420
cases_in_suite = [int (n ) for n in cases_in_suite ]
409
421
results = suite_info .get ("results" )
422
+ durations = suite_info .get ("durations" )
410
423
plan_title = expected_plan .get ("name" )
411
424
412
425
suite_entries = [
@@ -502,16 +515,18 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
502
515
"skipped" : {},
503
516
}
504
517
505
- for test_case , outcome in results .items ():
506
- logging .info (f"{ test_case } : { outcome } " )
518
+ for test_case in results .keys ():
519
+ outcome = results [test_case ]
520
+ duration = durations [test_case ]
521
+ logging .info (f"{ test_case } : { outcome } { duration } " )
507
522
if outcome == "rerun" :
508
523
logging .info ("Rerun result...skipping..." )
509
524
continue
510
525
category = next (status for status in passkey if outcome in passkey .get (status ))
511
526
if not test_results [category ].get (run_id ):
512
527
test_results [category ][run_id ] = []
513
528
test_results [category ][run_id ].append (
514
- {"suite_id" : suite_id , "test_case" : test_case }
529
+ {"suite_id" : suite_id , "test_case" : test_case , "duration" : f" { duration } s" }
515
530
)
516
531
517
532
return test_results
@@ -547,7 +562,9 @@ def collect_changes(testrail_session: TestRail, report):
547
562
548
563
version_str = metadata .get ("fx_version" )
549
564
plan_title = get_plan_title (version_str , channel )
550
- logging .info (plan_title )
565
+ logging .warning (
566
+ f"Got plan title: { plan_title } from version { version_str } and channel { channel } "
567
+ )
551
568
plan_match = PLAN_NAME_RE .match (plan_title )
552
569
(_ , major ) = [plan_match [n ] for n in range (1 , 3 )]
553
570
config = metadata .get ("machine_config" )
@@ -628,6 +645,7 @@ def collect_changes(testrail_session: TestRail, report):
628
645
last_suite_id = None
629
646
last_description = None
630
647
results_by_suite = {}
648
+ durations_by_suite = {}
631
649
full_test_results = {}
632
650
tests = [
633
651
test
@@ -655,11 +673,22 @@ def collect_changes(testrail_session: TestRail, report):
655
673
# Tests reported as rerun are a problem -- we need to know pass/fail
656
674
if outcome == "rerun" :
657
675
outcome = test .get ("call" ).get ("outcome" )
658
- logging .info (f"TC: { test_case } : { outcome } " )
676
+ duration = (
677
+ test ["setup" ]["duration" ]
678
+ + test ["call" ]["duration" ]
679
+ + test ["teardown" ]["duration" ]
680
+ )
681
+ logging .info (f"TC: { test_case } : { outcome } using { duration } s " )
659
682
660
683
if not results_by_suite .get (suite_id ):
661
684
results_by_suite [suite_id ] = {}
685
+ durations_by_suite [suite_id ] = {}
662
686
results_by_suite [suite_id ][test_case ] = outcome
687
+ durations_by_suite [suite_id ].setdefault (test_case , 0 )
688
+ durations_by_suite [suite_id ][test_case ] = round (
689
+ durations_by_suite [suite_id ][test_case ] + duration , 2
690
+ )
691
+
663
692
if suite_id != last_suite_id :
664
693
# When we get the last test_case in a suite, add entry, run, results
665
694
if last_suite_id :
@@ -674,6 +703,7 @@ def collect_changes(testrail_session: TestRail, report):
674
703
"config_id" : config_id ,
675
704
"cases" : cases_in_suite ,
676
705
"results" : results_by_suite [last_suite_id ],
706
+ "durations" : durations_by_suite [last_suite_id ],
677
707
}
678
708
679
709
full_test_results = merge_results (
@@ -694,6 +724,7 @@ def collect_changes(testrail_session: TestRail, report):
694
724
"config_id" : config_id ,
695
725
"cases" : cases_in_suite ,
696
726
"results" : results_by_suite [last_suite_id ],
727
+ "durations" : durations_by_suite [last_suite_id ],
697
728
}
698
729
699
730
logging .info (f"n run { last_suite_id } , { last_description } " )
@@ -706,6 +737,8 @@ def collect_changes(testrail_session: TestRail, report):
706
737
full_test_results = merge_results (
707
738
full_test_results , organize_entries (testrail_session , expected_plan , suite_info )
708
739
)
740
+ logging .warning (f"full test results: { full_test_results } " )
741
+
709
742
return full_test_results
710
743
711
744
0 commit comments