-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparse_junit.py
More file actions
48 lines (45 loc) · 1.46 KB
/
parse_junit.py
File metadata and controls
48 lines (45 loc) · 1.46 KB
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
import os
from junitparser import JUnitXml, Failure, Skipped, Error
import tempfile
import subprocess
def qxx(cmd):
proc = subprocess.Popen(cmd,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True,
)
stdout, stderr = proc.communicate()
return proc.returncode, stdout, stderr
def main():
tmpdir = tempfile.mkdtemp(prefix='test_reports')
print(tmpdir)
path = 'cases'
cases = os.listdir(path)
for case in cases:
#print(case)
if case != 'c.py':
continue
xml_file = os.path.join(tmpdir, f"{case}.xml")
cmd_list = ['pytest', os.path.join(path, case), '--junitxml', xml_file]
code, stdout, stderr = qxx(cmd_list)
if code !=0:
print(f"Execution failed with {code}")
print(stdout)
print(stderr)
exit(1)
with open(xml_file) as fh:
print(fh.read())
return
xml = JUnitXml.fromfile(xml_file)
for suite in xml:
#print(suite)
for case in suite:
#print(type(case))
print(case.name)
if case.result:
print(case.result)
if isinstance(case.result, Failure):
print(' failure ', case.result.message)
if isinstance(case.result, Skipped):
print(' skipped ', case.result.message)
main()