@@ -30,6 +30,8 @@ def main():
30
30
default = "ansible-lint-junit.xml" , action = "store" , help = "print XML to output file" )
31
31
parser .add_argument ("-v" , "--verbose" , dest = "verbose" , action = "store_true" ,
32
32
help = "print XML to console as command output" , default = False )
33
+ parser .add_argument ("-d" , "--dummy-test" , dest = "dummy" , action = "store_true" ,
34
+ help = "Adds single (1) dummy test if there were 0 tests and/or 0 errors" , default = False )
33
35
parser .add_argument ('--version' , action = 'version' ,
34
36
version = '%(prog)s {version}' .format (version = version ()))
35
37
@@ -50,42 +52,50 @@ def main():
50
52
errors_count = str (len (ansible_lint_output ) - 1 )
51
53
break
52
54
53
- testsuite = ET .SubElement (
54
- testsuites , "testsuite" , errors = errors_count , failures = "0" , tests = errors_count , time = "0" )
55
+ if arguments .dummy :
56
+ testsuite = ET .SubElement (
57
+ testsuites , "testsuite" , errors = errors_count , failures = "0" , tests = "1" , time = "0" )
55
58
56
- line_regex = re .compile ('^(.*?):(\\ d+?):\\ s(.*)$' )
57
-
58
- if 0 == len (ansible_lint_output ):
59
- ET .SubElement (testsuite , "testcase" , name = "dummy_testcase.py" )
59
+ ET .SubElement (testsuite , "testcase" ,
60
+ name = "dummy_testcase_ansible_lint_junit" )
60
61
else :
61
- parsed_lines = []
62
- for line in ansible_lint_output :
63
- if 0 < len (line ):
64
-
65
- line_match = line_regex .match (line )
66
-
67
- if not line_match :
68
- continue
69
-
70
- line_data = {
71
- "filename" : line_match .group (1 ),
72
- "line" : int (line_match .group (2 )),
73
- "error" : line_match .group (3 ),
74
- "text" : line_match .group (3 ),
75
- }
76
- parsed_lines .append (line_data )
77
-
78
- testcase = ET .SubElement (
79
- testsuite , "testcase" , name = "{}-{}" .format (line_data ['filename' ], len (parsed_lines )))
80
-
81
- ET .SubElement (
82
- testcase ,
83
- "failure" ,
84
- file = line_data ['filename' ],
85
- line = str (line_data ['line' ]),
86
- message = line_data ['error' ],
87
- type = "Ansible Lint"
88
- ).text = line_data ['error' ]
62
+ testsuite = ET .SubElement (
63
+ testsuites , "testsuite" , errors = errors_count , failures = "0" , tests = errors_count , time = "0" )
64
+
65
+ line_regex = re .compile ('^(.*?):(\\ d+?):\\ s(.*)$' )
66
+
67
+ if 0 == len (ansible_lint_output ):
68
+ ET .SubElement (testsuite , "testcase" ,
69
+ name = "dummy_testcase_ansible_lint_junit" )
70
+ else :
71
+ parsed_lines = []
72
+ for line in ansible_lint_output :
73
+ if 0 < len (line ):
74
+
75
+ line_match = line_regex .match (line )
76
+
77
+ if not line_match :
78
+ continue
79
+
80
+ line_data = {
81
+ "filename" : line_match .group (1 ),
82
+ "line" : int (line_match .group (2 )),
83
+ "error" : line_match .group (3 ),
84
+ "text" : line_match .group (3 ),
85
+ }
86
+ parsed_lines .append (line_data )
87
+
88
+ testcase = ET .SubElement (
89
+ testsuite , "testcase" , name = "{}-{}" .format (line_data ['filename' ], len (parsed_lines )))
90
+
91
+ ET .SubElement (
92
+ testcase ,
93
+ "failure" ,
94
+ file = line_data ['filename' ],
95
+ line = str (line_data ['line' ]),
96
+ message = line_data ['error' ],
97
+ type = "Ansible Lint"
98
+ ).text = line_data ['error' ]
89
99
90
100
xml_string = ET .tostring (testsuites , encoding = 'utf8' , method = 'xml' )
91
101
xml_nice = minidom .parseString (xml_string )
0 commit comments