From 093f6396a973bbbc7a9c60c8bd4edb2cc2b9cd54 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 5 Jan 2024 10:50:14 +0100 Subject: [PATCH] Adding MLD parser based on junit report from @bohmr --- scripts/parse_mld_xml.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/parse_mld_xml.py diff --git a/scripts/parse_mld_xml.py b/scripts/parse_mld_xml.py new file mode 100644 index 0000000000..1760b56258 --- /dev/null +++ b/scripts/parse_mld_xml.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import argparse +from xml.etree import ElementTree + +""" +Parse a junit report and create a MLD summary report. +""" + +# Main routine +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Parse a junit report and create a MLD summary report.') + parser.add_argument('xml_report',type=str,help='XML junit report input file, e.g. report-junit.xml') + parser.add_argument('csv_file',type=str,help='Output CSV file, e.g. mld.csv') + args = parser.parse_args() + xml_report = args.xml_report + csv_file = args.csv_file + + mld = {} + + tree = ElementTree.parse(xml_report) + + testsuite = tree.find(".//testsuite") + print(f"Found testsuite with {testsuite.get('tests')} tests and {testsuite.get('failures')} failures.") + + testcases = tree.findall(".//testcase") + + with open(csv_file,'w') as outfile: + for testcase in testcases: + failure = testcase.find(".//failure") + if failure is not None: + system_out = testcase.find(".//system-out") + for line in system_out.text.split('\n'): + if line.startswith('MLD:'): + mld_val = float(line.split()[1]) + fulltestname = testcase.get('file') + "::" + testcase.get('name') + mld[fulltestname] = mld_val + outfile.write(fulltestname + ';' + str(mld_val)+'\n') -- GitLab