Skip to content

Commit 840079a

Browse files
committed
Added handling of skipped xml entity for the testcase and skipped attribute for the testsuite
1 parent ad652e4 commit 840079a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

junit_xml/__init__.py

+29
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
the output of the testcase
2525
</error>
2626
</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>
2732
<testcase classname="testdb.directory" name="003-passed-test" time="10">
2833
<system-out>
2934
I am system output
@@ -63,6 +68,7 @@ def build_xml_doc(self):
6368
test_suite_attributes['name'] = str(self.name)
6469
test_suite_attributes['failures'] = str(len([c for c in self.test_cases if c.is_failure()]))
6570
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()]))
6672
test_suite_attributes['time'] = str(sum(c.elapsed_sec for c in self.test_cases if c.elapsed_sec))
6773
test_suite_attributes['tests'] = str(len(self.test_cases))
6874

@@ -115,6 +121,16 @@ def build_xml_doc(self):
115121
error_element.text = case.error_output
116122
test_case_element.append(error_element)
117123

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+
118134
# test stdout
119135
if case.stdout:
120136
stdout_element = ET.Element("system-out")
@@ -187,6 +203,8 @@ def __init__(self, name, classname=None, elapsed_sec=None, stdout=None, stderr=N
187203
self.error_output = None
188204
self.failure_message = None
189205
self.failure_output = None
206+
self.skipped_message = None
207+
self.skipped_output = None
190208

191209
def add_error_info(self, message=None, output=None):
192210
"""Adds an error message, output, or both to the test case"""
@@ -202,10 +220,21 @@ def add_failure_info(self, message=None, output=None):
202220
if output:
203221
self.failure_output = output
204222

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+
205230
def is_failure(self):
206231
"""returns true if this test case is a failure"""
207232
return self.failure_output or self.failure_message
208233

209234
def is_error(self):
210235
"""returns true if this test case is an error"""
211236
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

Comments
 (0)