in modules/testrail_integration.py [0:0]
def mark_results(testrail_session: TestRail, test_results):
"""For each type of result, and per run, mark tests to status in batches"""
logging.info(f"mark results: object\n{test_results}")
existing_results = {}
for category in ["passed", "skipped", "xfailed", "failed"]:
for run_id in test_results[category]:
if not existing_results.get(run_id):
existing_results[run_id] = testrail_session.get_test_results(run_id)
current_results = {
result.get("case_id"): result.get("status_id")
for result in existing_results[run_id]
}
suite_id = test_results[category][run_id][0].get("suite_id")
all_test_cases = [
result.get("test_case") for result in test_results[category][run_id]
]
# Don't set passed tests to another status.
test_cases = [tc for tc in all_test_cases if current_results.get(tc) != 1]
logging.warn(
f"Setting the following test cases in run {run_id} to {category}: {test_cases}"
)
testrail_session.update_test_cases(
test_results.get("project_id"),
testrail_run_id=run_id,
testrail_suite_id=suite_id,
test_case_ids=test_cases,
status=category,
)