diff --git a/tools/stats/upload_test_stats.py b/tools/stats/upload_test_stats.py index 45a390fc5051d..aec191aa44904 100644 --- a/tools/stats/upload_test_stats.py +++ b/tools/stats/upload_test_stats.py @@ -49,7 +49,12 @@ def parse_xml_report( test_cases: list[dict[str, Any]] = [] - root = ET.parse(report) + try: + root = ET.parse(report) + except: + print(f"Warning: Could not parse {report}, skipping") + return test_cases + for test_case in root.iter(tag): case = process_xml_element(test_case) case["workflow_id"] = workflow_id @@ -83,7 +88,8 @@ def process_xml_element( # # becomes: # {"name": "test_foo", "classname": "test_bar"} - ret.update(element.attrib) + if element.attrib: + ret.update(element.attrib) # The XML format encodes all values as strings. Convert to ints/floats if # possible to make aggregation possible in SQL. @@ -201,22 +207,25 @@ def init_value(test_case: dict[str, Any]) -> dict[str, Any]: ret = {} for test_case in test_cases: - key = get_key(test_case) - if key not in ret: - ret[key] = init_value(test_case) - - ret[key]["tests"] += 1 - - if "failure" in test_case: - ret[key]["failures"] += 1 - elif "error" in test_case: - ret[key]["errors"] += 1 - elif "skipped" in test_case: - ret[key]["skipped"] += 1 - else: - ret[key]["successes"] += 1 - - ret[key]["time"] += test_case["time"] + try: + key = get_key(test_case) + if key not in ret: + ret[key] = init_value(test_case) + + ret[key]["tests"] += 1 + + if "failure" in test_case: + ret[key]["failures"] += 1 + elif "error" in test_case: + ret[key]["errors"] += 1 + elif "skipped" in test_case: + ret[key]["skipped"] += 1 + else: + ret[key]["successes"] += 1 + + ret[key]["time"] += test_case.get("time", 0) + except: + continue return list(ret.values()) @@ -247,7 +256,11 @@ def init_value(test_case: dict[str, Any]) -> dict[str, Any]: print(f"Workflow id is: {args.workflow_run_id}") - test_cases = get_tests(args.workflow_run_id, args.workflow_run_attempt) + try: + test_cases = get_tests(args.workflow_run_id, args.workflow_run_attempt) + except Exception as e: + print(f"Error getting tests: {e}") + test_cases = [] # Flush stdout so that any errors in the upload show up last in the logs. sys.stdout.flush()