Paste P7797

T188717 parse-testsuites.py
ActivePublic

Authored by hashar on Tue, Nov 13, 12:33 PM.
#!/usr/bin/env python3
import argparse
import xml.etree.ElementTree as ET
parser = argparse.ArgumentParser()
parser.add_argument('file', help='Junit file to process')
args = parser.parse_args()
testsuites = ET.parse(args.file).findall('.//testsuite')
for testsuite in testsuites:
msg = '{name}'
skipped = (
'skipped' in testsuite.attrib
and int(testsuite.attrib['skipped']) > 0
)
no_tests = (
int(testsuite.attrib['tests']) == 0
and int(testsuite.attrib['assertions']) == 0
)
if skipped or no_tests:
msg = msg + ' SKIPPED'
else:
msg = msg + ' {tests} tests'
try:
print(msg.format_map(testsuite.attrib))
except KeyError as e:
print('Missing key in ', testsuite.attrib)
raise e