Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions tools/stats/upload_test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,7 +88,8 @@ def process_xml_element(
# <testcase name="test_foo" classname="test_bar"></testcase>
# 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.
Expand Down Expand Up @@ -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())


Expand Down Expand Up @@ -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()
Expand Down