-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadXUnitTestResults.py
65 lines (60 loc) · 2.09 KB
/
readXUnitTestResults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from xml.dom.minidom import parse
import sys
def readXmlFromFile(file):
with open(file) as f:
return parse(file)
def getParentTest(elem):
parent = elem.parentNode
return parent.getAttribute("name") + " in " + parent.getAttribute("classname")
def readResultsFromXUnitXml(xml):
doc = xml.documentElement
count_t = int(doc.getAttribute("tests"))
count_e = int(doc.getAttribute("errors"))
count_f = int(doc.getAttribute("failures"))
errors = None
failures = None
if count_e > 0:
elems = doc.getElementsByTagName("error")
errors = [getParentTest(error) for error in elems]
if count_f > 0:
elems = doc.getElementsByTagName("failure")
failures = [getParentTest(error) for error in elems]
return count_t, count_e, count_f, errors, failures
def readTestResultsFromFiles(files):
count_t = 0
count_e = 0
count_f = 0
errors = None
failures = None
for file in files:
xml = readXmlFromFile(file)
t1, e1, f1, errs, fails = readResultsFromXUnitXml(xml)
count_t += t1
count_e += e1
count_f += f1
if errs is not None:
if errors is None:
errors = errs
else:
errors.extend(errs)
if fails is not None:
if failures is None:
failures = fails
else:
failures.extend(fails)
return count_t, count_e, count_f, errors, failures
if __name__ == '__main__':
count_t, count_e, count_f,errors, failures = readTestResultsFromFiles(sys.argv[1:])
print("Total tests: " + str(count_t))
if count_e + count_f == 0:
print("Success!")
else:
if errors is not None:
print(str(count_e) + " test(s) in error:")
for error in errors:
print(" " + error)
if failures is not None:
print(str(count_f) + " failing test(s):")
for failure in failures:
print(" " + failure)
sys.exit(-1) #raise Exception("Tests in error: " + str(count_e) + ", failing tests: " + str(count_f))