Created
February 18, 2023 00:17
-
-
Save wyattearp/a51a6dfb5706d11efee751930d06b84c to your computer and use it in GitHub Desktop.
Generate a summary of Junit unit data from potentially multiple test suites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# If it doesn't work, blame ChatGPT because I asked it to do this while I was fixing something else | |
import xml.etree.ElementTree as ET | |
import argparse | |
def summarize_junit_results(file_path): | |
try: | |
tree = ET.parse(file_path) | |
root = tree.getroot() | |
except (ET.ParseError, FileNotFoundError) as e: | |
print(f"Error: {e}") | |
return | |
total_tests = 0 | |
total_failures = 0 | |
total_errors = 0 | |
total_skipped = 0 | |
for testsuite in root.findall('testsuite'): | |
total_tests += int(testsuite.get("tests") or 0) | |
total_failures += int(testsuite.get("failures") or 0) | |
total_errors += int(testsuite.get("errors") or 0) | |
total_skipped += int(testsuite.get("skipped") or 0) | |
print(f"Total tests: {total_tests}") | |
print(f"Total failures: {total_failures}") | |
print(f"Total errors: {total_errors}") | |
print(f"Total skipped: {total_skipped}") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file_path", help="path to the JUnit XML file") | |
args = parser.parse_args() | |
summarize_junit_results(args.file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment