Skip to content

Commit 777c971

Browse files
committed
Modified tri and tr
1 parent c87c41d commit 777c971

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

modules/testrail.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def update_test_cases(
391391
testrail_suite_id,
392392
test_case_ids=[],
393393
status="passed",
394+
elapsed=[]
394395
):
395396
"""Given a project id, a run id, and a suite id, for each case given a status,
396397
update the test objects with the correct status code"""
@@ -408,13 +409,19 @@ def update_test_cases(
408409
testrail_project_id, testrail_suite_id
409410
)
410411
]
411-
data = {
412-
"results": [
413-
{"case_id": test_case_id, "status_id": status_key.get(status)}
414-
for test_case_id in test_case_ids
415-
]
416-
}
417-
return self._update_test_run_results(testrail_run_id, data)
412+
413+
results = []
414+
for i in range(len(test_case_ids)):
415+
results.append(
416+
{
417+
"case_id": test_case_ids[i],
418+
"status_id": status_key.get(status),
419+
"elapsed": elapsed[i]
420+
}
421+
)
422+
logging.warning(f"Going to update cases with payload: {results}")
423+
424+
return self._update_test_run_results(testrail_run_id, {"results": results})
418425

419426
# Private Methods
420427

modules/testrail_integration.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,33 @@ def mark_results(testrail_session: TestRail, test_results):
245245
for result in existing_results[run_id]
246246
}
247247
suite_id = test_results[category][run_id][0].get("suite_id")
248-
all_test_cases = [
249-
result.get("test_case") for result in test_results[category][run_id]
250-
]
248+
249+
all_test_cases = []
250+
all_durations = []
251+
for result in test_results[category][run_id]:
252+
all_test_cases.append(result.get("test_case"))
253+
all_durations.append(result.get("duration"))
251254

252255
# Don't set passed tests to another status.
253-
test_cases = [tc for tc in all_test_cases if current_results.get(tc) != 1]
256+
test_cases_ids = []
257+
durations = []
258+
for i, tc in enumerate(all_test_cases):
259+
if current_results.get(tc) != 1:
260+
test_cases_ids.append(tc)
261+
durations.append(all_durations[i])
254262
logging.warning(
255-
f"Setting the following test cases in run {run_id} to {category}: {test_cases}"
263+
f"Setting the following test cases in run {run_id} to {category}: {test_cases_ids}"
264+
)
265+
logging.warning(
266+
f"Setting the following test cases {test_cases_ids} to duration {durations}"
256267
)
257268
testrail_session.update_test_cases(
258269
test_results.get("project_id"),
259270
testrail_run_id=run_id,
260271
testrail_suite_id=suite_id,
261-
test_case_ids=test_cases,
272+
test_case_ids=test_cases_ids,
262273
status=category,
274+
elapsed=durations
263275
)
264276

265277

@@ -406,6 +418,7 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
406418
cases_in_suite = suite_info.get("cases")
407419
cases_in_suite = [int(n) for n in cases_in_suite]
408420
results = suite_info.get("results")
421+
durations = suite_info.get("durations")
409422
plan_title = expected_plan.get("name")
410423

411424
suite_entries = [
@@ -501,16 +514,18 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
501514
"skipped": {},
502515
}
503516

504-
for test_case, outcome in results.items():
505-
logging.info(f"{test_case}: {outcome}")
517+
for test_case in results.keys():
518+
outcome = results[test_case]
519+
duration = durations[test_case]
520+
logging.info(f"{test_case}: {outcome} {duration}")
506521
if outcome == "rerun":
507522
logging.info("Rerun result...skipping...")
508523
continue
509524
category = next(status for status in passkey if outcome in passkey.get(status))
510525
if not test_results[category].get(run_id):
511526
test_results[category][run_id] = []
512527
test_results[category][run_id].append(
513-
{"suite_id": suite_id, "test_case": test_case}
528+
{"suite_id": suite_id, "test_case": test_case, "duration": f"{duration}s"}
514529
)
515530

516531
return test_results
@@ -546,7 +561,7 @@ def collect_changes(testrail_session: TestRail, report):
546561

547562
version_str = metadata.get("fx_version")
548563
plan_title = get_plan_title(version_str, channel)
549-
logging.info(plan_title)
564+
logging.warning(f"Got plan title: {plan_title} from version {version_str} and channel {channel}")
550565
plan_match = PLAN_NAME_RE.match(plan_title)
551566
(_, major) = [plan_match[n] for n in range(1, 3)]
552567
config = metadata.get("machine_config")
@@ -627,6 +642,7 @@ def collect_changes(testrail_session: TestRail, report):
627642
last_suite_id = None
628643
last_description = None
629644
results_by_suite = {}
645+
durations_by_suite = {}
630646
full_test_results = {}
631647
tests = [
632648
test
@@ -654,11 +670,16 @@ def collect_changes(testrail_session: TestRail, report):
654670
# Tests reported as rerun are a problem -- we need to know pass/fail
655671
if outcome == "rerun":
656672
outcome = test.get("call").get("outcome")
657-
logging.info(f"TC: {test_case}: {outcome}")
673+
duration = test['setup']['duration'] + test['call']['duration'] + test['teardown']['duration']
674+
logging.info(f"TC: {test_case}: {outcome} using {duration}s ")
658675

659676
if not results_by_suite.get(suite_id):
660677
results_by_suite[suite_id] = {}
678+
durations_by_suite[suite_id] = {}
661679
results_by_suite[suite_id][test_case] = outcome
680+
durations_by_suite[suite_id].setdefault(test_case, 0)
681+
durations_by_suite[suite_id][test_case] = round(durations_by_suite[suite_id][test_case] + duration, 2)
682+
662683
if suite_id != last_suite_id:
663684
# When we get the last test_case in a suite, add entry, run, results
664685
if last_suite_id:
@@ -673,6 +694,7 @@ def collect_changes(testrail_session: TestRail, report):
673694
"config_id": config_id,
674695
"cases": cases_in_suite,
675696
"results": results_by_suite[last_suite_id],
697+
"durations": durations_by_suite[last_suite_id]
676698
}
677699

678700
full_test_results = merge_results(
@@ -693,6 +715,7 @@ def collect_changes(testrail_session: TestRail, report):
693715
"config_id": config_id,
694716
"cases": cases_in_suite,
695717
"results": results_by_suite[last_suite_id],
718+
"durations": durations_by_suite[last_suite_id]
696719
}
697720

698721
logging.info(f"n run {last_suite_id}, {last_description}")
@@ -705,6 +728,8 @@ def collect_changes(testrail_session: TestRail, report):
705728
full_test_results = merge_results(
706729
full_test_results, organize_entries(testrail_session, expected_plan, suite_info)
707730
)
731+
logging.warning(f"full test results: {full_test_results}")
732+
708733
return full_test_results
709734

710735

0 commit comments

Comments
 (0)