Ticket #16567: junit_difference.py

File junit_difference.py, 1.3 KB (added by taylor.smock, 6 months ago)

Show tests that have different numbers of passed/failed tests

Line 
1#!/usr/bin/env python3
2import os
3import glob
4import xml.etree.ElementTree as ET
5
6directories = ["report-junit4", "report-junit5"]
7
8def status(directory, filename):
9        tree = ET.parse(os.path.join(directory, filename))
10        root = tree.getroot()
11        try:
12            name = root.attrib['name']
13        except KeyError as e:
14            print(filename)
15            print(root.attrib)
16            raise e
17        tests = {}
18        for key in ['tests', 'errors', 'failures', 'skipped', 'aborted']:
19            if key in root.attrib and int(root.attrib[key]) > 0:
20                tests[key] = root.attrib[key]
21        return tests
22
23def compare(filename):
24    rname = filename
25    if "TEST" not in filename and ".xml" not in filename:
26        rname = "TEST-{}.xml".format(filename)
27    tstatus = []
28    for directory in directories:
29        tstatus.append(status(directory, rname))
30    return tstatus[0] == tstatus[1]
31
32if __name__ == "__main__":
33    files = glob.glob(os.path.join(directories[0], 'TEST*.xml'))
34    files = [os.path.basename(x) for x in files]
35    files = [x for x in files if x not in ["TESTS-TestSuites.xml"]]
36    for filename in files:
37        if not compare(filename):
38            print(filename)
39            for i in directories:
40                print("{}: {}".format(i, status(i, filename)))