24
24
the output of the testcase
25
25
</error>
26
26
</testcase>
27
+ <testcase classname="package.directory" name="003-skipped-test" time="0">
28
+ <skipped message="SKIPPED Test" type="skipped">
29
+ the output of the testcase
30
+ </skipped>
31
+ </testcase>
27
32
<testcase classname="testdb.directory" name="003-passed-test" time="10">
28
33
<system-out>
29
34
I am system output
@@ -63,6 +68,7 @@ def build_xml_doc(self):
63
68
test_suite_attributes ['name' ] = str (self .name )
64
69
test_suite_attributes ['failures' ] = str (len ([c for c in self .test_cases if c .is_failure ()]))
65
70
test_suite_attributes ['errors' ] = str (len ([c for c in self .test_cases if c .is_error ()]))
71
+ test_suite_attributes ['skipped' ] = str (len ([c for c in self .test_cases if c .is_skipped ()]))
66
72
test_suite_attributes ['time' ] = str (sum (c .elapsed_sec for c in self .test_cases if c .elapsed_sec ))
67
73
test_suite_attributes ['tests' ] = str (len (self .test_cases ))
68
74
@@ -115,6 +121,16 @@ def build_xml_doc(self):
115
121
error_element .text = case .error_output
116
122
test_case_element .append (error_element )
117
123
124
+ # skippeds
125
+ if case .is_skipped ():
126
+ attrs = {'type' : 'skipped' }
127
+ if case .skipped_message :
128
+ attrs ['message' ] = case .skipped_message
129
+ skipped_element = ET .Element ("skipped" , attrs )
130
+ if case .error_output :
131
+ skipped_element .text = case .skipped_output
132
+ test_case_element .append (skipped_element )
133
+
118
134
# test stdout
119
135
if case .stdout :
120
136
stdout_element = ET .Element ("system-out" )
@@ -130,7 +146,7 @@ def build_xml_doc(self):
130
146
return xml_element
131
147
132
148
@staticmethod
133
- def to_xml_string (test_suites , prettyprint = True ):
149
+ def to_xml_string (test_suites , prettyprint = True , encoding = None ):
134
150
"""Returns the string representation of the JUnit XML document"""
135
151
try :
136
152
iter (test_suites )
@@ -141,17 +157,17 @@ def to_xml_string(test_suites, prettyprint=True):
141
157
for ts in test_suites :
142
158
xml_element .append (ts .build_xml_doc ())
143
159
144
- xml_string = ET .tostring (xml_element )
160
+ xml_string = ET .tostring (xml_element , encoding = encoding )
145
161
xml_string = TestSuite ._clean_illegal_xml_chars (xml_string )
146
162
147
163
if prettyprint :
148
164
xml_string = xml .dom .minidom .parseString (xml_string ).toprettyxml ()
149
165
return xml_string
150
166
151
167
@staticmethod
152
- def to_file (file_descriptor , test_suites , prettyprint = True ):
168
+ def to_file (file_descriptor , test_suites , prettyprint = True , encoding = None ):
153
169
"""Writes the JUnit XML document to file"""
154
- file_descriptor .write (TestSuite .to_xml_string (test_suites , prettyprint ))
170
+ file_descriptor .write (TestSuite .to_xml_string (test_suites , prettyprint , encoding ))
155
171
156
172
@staticmethod
157
173
def _clean_illegal_xml_chars (string_to_clean ):
@@ -187,6 +203,8 @@ def __init__(self, name, classname=None, elapsed_sec=None, stdout=None, stderr=N
187
203
self .error_output = None
188
204
self .failure_message = None
189
205
self .failure_output = None
206
+ self .skipped_message = None
207
+ self .skipped_output = None
190
208
191
209
def add_error_info (self , message = None , output = None ):
192
210
"""Adds an error message, output, or both to the test case"""
@@ -202,10 +220,21 @@ def add_failure_info(self, message=None, output=None):
202
220
if output :
203
221
self .failure_output = output
204
222
223
+ def add_skipped_info (self , message = None , output = None ):
224
+ """Adds a skipped message, output, or both to the test case"""
225
+ if message :
226
+ self .skipped_message = message
227
+ if output :
228
+ self .skipped_output = output
229
+
205
230
def is_failure (self ):
206
231
"""returns true if this test case is a failure"""
207
232
return self .failure_output or self .failure_message
208
233
209
234
def is_error (self ):
210
235
"""returns true if this test case is an error"""
211
236
return self .error_output or self .error_message
237
+
238
+ def is_skipped (self ):
239
+ """returns true if this test case has been skipped"""
240
+ return self .skipped_output or self .skipped_message
0 commit comments