diff --git a/resources/merge-junit-results.py b/resources/merge-junit-results.py index 6f1eec5..82783a8 100755 --- a/resources/merge-junit-results.py +++ b/resources/merge-junit-results.py @@ -4,6 +4,7 @@ # import os +import re import sys import xml.etree.ElementTree as ET @@ -26,6 +27,9 @@ def main(): merge_results(args[:]) +JUNIT_RE = re.compile('junit-(.*?)(-results?)?.xml') + + def merge_results(xml_files): failures = 0 tests = 0 @@ -35,23 +39,27 @@ def merge_results(xml_files): for file_name in xml_files: tree = ET.parse(file_name) - test_suite = tree.getroot() - failures += int(test_suite.attrib.get('failures', '0')) - tests += int(test_suite.attrib.get('tests', '0')) - errors += int(test_suite.attrib.get('errors', '0')) - time += float(test_suite.attrib.get('time', '0.')) - name = test_suite.attrib.get('name', '') - for child in test_suite.getchildren(): - child.attrib['classname'] = '%s-%s' % (name, child.attrib.get('classname', '')) - cases.append(test_suite.getchildren()) + name = JUNIT_RE.match(file_name) + if name: + name = name.group(1) + test_suites = tree.getroot() + for test_suite in test_suites: + failures += int(test_suite.attrib.get('failures', '0')) + tests += int(test_suite.attrib.get('tests', '0')) + errors += int(test_suite.attrib.get('errors', '0')) + time += float(test_suite.attrib.get('time', '0.')) + for test_case in test_suite.findall('testcase'): + if name: + test_case.attrib['classname'] = '%s.%s' % (name, test_case.attrib.get('classname', '')) + cases.append(test_case) - new_root = ET.Element('testsuite') - new_root.attrib['failures'] = '%s' % failures - new_root.attrib['tests'] = '%s' % tests - new_root.attrib['errors'] = '%s' % errors - new_root.attrib['time'] = '%s' % time - for case in cases: - new_root.extend(case) + new_root = ET.Element('testsuites') + test_suite = ET.SubElement(new_root, 'testsuite') + test_suite.attrib['failures'] = '%s' % failures + test_suite.attrib['tests'] = '%s' % tests + test_suite.attrib['errors'] = '%s' % errors + test_suite.attrib['time'] = '%s' % time + test_suite.extend(cases) new_tree = ET.ElementTree(new_root) ET.dump(new_tree)