caellion-python-commons: parse-tests.py Source File

caellion-python-commons

parse-tests.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """!
3 This script parses test results, adding Linux or Windows prefix to test names.
4 """
5 import xml.etree.ElementTree as ET
6 import os
7
8 if os.path.isfile("reports/nose2-junit.xml"):
9 tree = ET.parse("reports/nose2-junit.xml")
10 root = tree.getroot()
11 root.set("name", "pytest-linux")
12 for element in root:
13 if element.tag == "testsuite":
14 element.set("name", "pytest-linux")
15 for subelement in element:
16 if subelement.tag == "testcase":
17 classname = subelement.get("classname")
18 classname = classname.split(".")
19 del classname[0]
20 classname = "Linux." + ".".join(classname)
21 subelement.set("classname", classname)
22 tree.write("reports/nose2-junit.xml",
23 encoding="UTF-8", xml_declaration=False)
24
25 if os.path.isfile("reports/nose2-junit-windows.xml"):
26 tree = ET.parse("reports/nose2-junit-windows.xml")
27 root = tree.getroot()
28 root.set("name", "pytest-windows")
29 for element in root:
30 if element.tag == "testsuite":
31 element.set("name", "pytest-windows")
32 for subelement in element:
33 if subelement.tag == "testcase":
34 classname = subelement.get("classname")
35 classname = classname.split(".")
36 del classname[0]
37 classname = "Windows." + ".".join(classname)
38 subelement.set("classname", classname)
39 tree.write("reports/nose2-junit-windows.xml",
40 encoding="UTF-8", xml_declaration=False)