@@ -216,6 +216,12 @@ def mark_results(testrail_session: TestRail, test_results):
216
216
result .get ("test_case" ) for result in test_results [category ][run_id ]
217
217
]
218
218
219
+ # Organize durations
220
+ durations = test_results [category ][run_id ].get ("durations" )
221
+ durations_info = {
222
+ tc : {"elapsed" : f"{ durations .get (tc )} s" } for tc in durations
223
+ }
224
+
219
225
# Don't set passed tests to another status.
220
226
test_cases = [tc for tc in all_test_cases if current_results .get (tc ) != 1 ]
221
227
logging .warn (
@@ -227,6 +233,7 @@ def mark_results(testrail_session: TestRail, test_results):
227
233
testrail_suite_id = suite_id ,
228
234
test_case_ids = test_cases ,
229
235
status = category ,
236
+ more_results = durations_info ,
230
237
)
231
238
232
239
@@ -251,6 +258,7 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
251
258
cases_in_suite = suite_info .get ("cases" )
252
259
cases_in_suite = [int (n ) for n in cases_in_suite ]
253
260
results = suite_info .get ("results" )
261
+ durations = suite_info .get ("durations" )
254
262
plan_title = expected_plan .get ("name" )
255
263
256
264
suite_entries = [
@@ -355,7 +363,11 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
355
363
if not test_results [category ].get (run_id ):
356
364
test_results [category ][run_id ] = []
357
365
test_results [category ][run_id ].append (
358
- {"suite_id" : suite_id , "test_case" : test_case }
366
+ {
367
+ "suite_id" : suite_id ,
368
+ "test_case" : test_case ,
369
+ "duration" : durations .get (test_case ),
370
+ }
359
371
)
360
372
361
373
return test_results
@@ -469,6 +481,7 @@ def collect_changes(testrail_session: TestRail, report):
469
481
last_suite_id = None
470
482
last_description = None
471
483
results_by_suite = {}
484
+ durations_by_suite = {}
472
485
full_test_results = {}
473
486
tests = [
474
487
test
@@ -498,9 +511,20 @@ def collect_changes(testrail_session: TestRail, report):
498
511
outcome = test .get ("call" ).get ("outcome" )
499
512
logging .info (f"TC: { test_case } : { outcome } " )
500
513
514
+ duration = round (
515
+ test .get ("setup" ).get ("duration" )
516
+ + test .get ("call" ).get ("duration" )
517
+ + test .get ("teardown" ).get ("duration" )
518
+ )
519
+
501
520
if not results_by_suite .get (suite_id ):
502
521
results_by_suite [suite_id ] = {}
503
522
results_by_suite [suite_id ][test_case ] = outcome
523
+
524
+ if not durations_by_suite .get (suite_id ):
525
+ durations_by_suite [suite_id ] = {}
526
+ durations_by_suite [suite_id ][test_case ] = duration
527
+
504
528
if suite_id != last_suite_id :
505
529
# When we get the last test_case in a suite, add entry, run, results
506
530
if last_suite_id :
@@ -515,6 +539,7 @@ def collect_changes(testrail_session: TestRail, report):
515
539
"config_id" : config_id ,
516
540
"cases" : cases_in_suite ,
517
541
"results" : results_by_suite [last_suite_id ],
542
+ "durations" : durations_by_suite [last_suite_id ],
518
543
}
519
544
520
545
full_test_results = merge_results (
@@ -535,6 +560,7 @@ def collect_changes(testrail_session: TestRail, report):
535
560
"config_id" : config_id ,
536
561
"cases" : cases_in_suite ,
537
562
"results" : results_by_suite [last_suite_id ],
563
+ "durations" : durations_by_suite [last_suite_id ],
538
564
}
539
565
540
566
logging .info (f"n run { last_suite_id } , { last_description } " )
0 commit comments