def parse_junit_xml()

in tools/build/junit_summary.py [0:0]


def parse_junit_xml(file):
    try:
        tree = ET.parse(file)
        root = tree.getroot()
        
        # Extract main test summary from the first-level testsuite (overall summary)
        main_suite = root.find("./testsuite[@name='']")
        if main_suite is None:
            main_suite = root.find("./testsuite")
        
        total_tests = int(main_suite.attrib.get("tests", 0))
        total_failures = int(main_suite.attrib.get("failures", 0))
        total_errors = int(main_suite.attrib.get("errors", 0))
        total_skipped = int(main_suite.attrib.get("skipped", 0))
        total_time = float(main_suite.attrib.get("time", 0))
        passed_tests = total_tests - total_failures - total_errors - total_skipped
        
        failures = []
        # Extract failures from nested test suites
        for ts in root.findall(".//testsuite[@name!='']"):
            for tc in ts.findall("testcase[failure]"):
                class_name = tc.attrib.get("classname", "Unknown")
                test_name = tc.attrib.get("name", "Unknown")
                file_path = tc.attrib.get("file", "Unknown")
                line = tc.attrib.get("line", "Unknown")
                failure_message = tc.find("failure").text.strip() if tc.find("failure") is not None else "Unknown"
                failure_message = failure_message.replace("\n", "<br>")  # Convert newlines to Markdown format
                failures.append((class_name, test_name, f"{file_path}:{line}", failure_message))
        
        return file, passed_tests, total_failures, total_skipped, total_errors, total_time, failures
    except Exception as e:
        print(f"Error processing {file}: {e}")
        return file, 0, 0, 0, 0, 0.0, []