Paste P7796

T188717 parse-testcases.py
ActivePublic

Authored by hashar on Tue, Nov 13, 12:32 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()
testcases = ET.parse(args.file).findall('.//testcase')
for testcase in testcases:
msg = '{name}'
no_assertions = 'assertions' not in testcase.attrib
zero_assertions = int(testcase.attrib.get('assertions', 0))
if no_assertions or zero_assertions == 0:
msg = msg + ' SKIPPED'
else:
msg = msg + ' {assertions} assertions'
try:
print(msg.format_map(testcase.attrib))
except KeyError as e:
print('Missing key in ', testcase.attrib)
raise e