Skip to content

Commit a12201b

Browse files
authored
Merge pull request kyrus#41 from wachambo/jenkinsci/add-tc-attributes
Added test case attributes
2 parents 450e7c8 + 7bf4a56 commit a12201b

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

junit_xml/__init__.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,26 @@ def build_xml_doc(self, encoding=None):
138138
for case in self.test_cases:
139139
test_case_attributes = dict()
140140
test_case_attributes['name'] = decode(case.name, encoding)
141+
if case.assertions:
142+
test_case_attributes['assertions'] = decode(case.assertions, encoding)
141143
if case.elapsed_sec:
142144
test_case_attributes['time'] = "%f" % case.elapsed_sec
145+
if case.timestamp:
146+
test_case_attributes['timestamp'] = decode(case.timestamp, encoding)
143147
if case.classname:
144148
test_case_attributes['classname'] = decode(case.classname, encoding)
149+
if case.status:
150+
test_case_attributes['status'] = decode(case.status, encoding)
151+
if case.category:
152+
test_case_attributes['class'] = decode(case.category, encoding)
153+
if case.file:
154+
test_case_attributes['file'] = decode(case.file, encoding)
155+
if case.line:
156+
test_case_attributes['line'] = decode(case.line, encoding)
157+
if case.log:
158+
test_case_attributes['log'] = decode(case.log, encoding)
159+
if case.url:
160+
test_case_attributes['url'] = decode(case.url, encoding)
145161

146162
test_case_element = ET.SubElement(
147163
xml_element, "testcase", test_case_attributes)
@@ -250,7 +266,7 @@ def to_file(file_descriptor, test_suites, prettyprint=True, encoding=None):
250266
def _clean_illegal_xml_chars(string_to_clean):
251267
"""
252268
Removes any illegal unicode characters from the given XML string.
253-
269+
254270
@see: http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
255271
"""
256272

@@ -275,13 +291,23 @@ def _clean_illegal_xml_chars(string_to_clean):
275291
class TestCase(object):
276292
"""A JUnit test case with a result and possibly some stdout or stderr"""
277293

278-
def __init__(self, name, classname=None, elapsed_sec=None, stdout=None,
279-
stderr=None):
294+
def __init__(self, name, assertions=None, elapsed_sec=None,
295+
timestamp=None, classname=None, status=None, category=None, file=None, line=None,
296+
log=None, group=None, url=None, stdout=None, stderr=None):
280297
self.name = name
298+
self.assertions = assertions
281299
self.elapsed_sec = elapsed_sec
300+
self.timestamp = timestamp
301+
self.classname = classname
302+
self.status = status
303+
self.category = category
304+
self.file = file
305+
self.line = line
306+
self.log = log
307+
self.url = url
282308
self.stdout = stdout
283309
self.stderr = stderr
284-
self.classname = classname
310+
285311
self.error_message = None
286312
self.error_output = None
287313
self.error_type = None

test_junit_xml.py

+35-15
Original file line numberDiff line numberDiff line change
@@ -251,23 +251,35 @@ def test_init(self):
251251

252252
def test_init_classname(self):
253253
(ts, tcs) = serialize_and_read(
254-
TestSuite('test', [TestCase('Test1', 'some.class.name')]))[0]
254+
TestSuite('test',
255+
[TestCase(name='Test1', classname='some.class.name')]))[0]
255256
verify_test_case(
256257
self, tcs[0], {'name': 'Test1', 'classname': 'some.class.name'})
257258

258259
def test_init_classname_time(self):
259260
(ts, tcs) = serialize_and_read(
260261
TestSuite('test',
261-
[TestCase('Test1', 'some.class.name', 123.345)]))[0]
262+
[TestCase(name='Test1', classname='some.class.name',
263+
elapsed_sec=123.345)]))[0]
262264
verify_test_case(
263265
self, tcs[0], {'name': 'Test1', 'classname': 'some.class.name',
264266
'time': ("%f" % 123.345)})
265267

268+
def test_init_classname_time_timestamp(self):
269+
(ts, tcs) = serialize_and_read(
270+
TestSuite('test',
271+
[TestCase(name='Test1', classname='some.class.name',
272+
elapsed_sec=123.345, timestamp=99999)]))[0]
273+
verify_test_case(
274+
self, tcs[0], {'name': 'Test1', 'classname': 'some.class.name',
275+
'time': ("%f" % 123.345),
276+
'timestamp': ("%s" % 99999)})
277+
266278
def test_init_stderr(self):
267279
(ts, tcs) = serialize_and_read(
268280
TestSuite(
269-
'test', [TestCase('Test1', 'some.class.name', 123.345,
270-
stderr='I am stderr!')]))[0]
281+
'test', [TestCase(name='Test1', classname='some.class.name',
282+
elapsed_sec=123.345, stderr='I am stderr!')]))[0]
271283
verify_test_case(
272284
self, tcs[0],
273285
{'name': 'Test1', 'classname': 'some.class.name',
@@ -277,8 +289,9 @@ def test_init_stdout_stderr(self):
277289
(ts, tcs) = serialize_and_read(
278290
TestSuite(
279291
'test', [TestCase(
280-
'Test1', 'some.class.name', 123.345, 'I am stdout!',
281-
'I am stderr!')]))[0]
292+
name='Test1', classname='some.class.name',
293+
elapsed_sec=123.345, stdout='I am stdout!',
294+
stderr='I am stderr!')]))[0]
282295
verify_test_case(
283296
self, tcs[0],
284297
{'name': 'Test1', 'classname': 'some.class.name',
@@ -414,9 +427,12 @@ def test_init_illegal_unicode_char(self):
414427
"failure message with illegal unicode char: []"))
415428

416429
def test_init_utf8(self):
417-
tc = TestCase('Test äöü', 'some.class.name.äöü', 123.345, 'I am stdöüt!', 'I am stdärr!')
430+
tc = TestCase(name='Test äöü', classname='some.class.name.äöü',
431+
elapsed_sec=123.345, stdout='I am stdöüt!',
432+
stderr='I am stdärr!')
418433
tc.add_skipped_info(message='Skipped äöü', output="I skippäd!")
419-
tc.add_error_info(message='Skipped error äöü', output="I skippäd with an error!")
434+
tc.add_error_info(message='Skipped error äöü',
435+
output="I skippäd with an error!")
420436
test_suite = TestSuite('Test UTF-8', [tc])
421437
(ts, tcs) = serialize_and_read(test_suite, encoding='utf-8')[0]
422438
verify_test_case(self, tcs[0], {'name': decode('Test äöü', 'utf-8'),
@@ -429,8 +445,11 @@ def test_init_utf8(self):
429445
error_output=decode('I skippäd with an error!', 'utf-8'))
430446

431447
def test_init_unicode(self):
432-
tc = TestCase(decode('Test äöü', 'utf-8'), decode('some.class.name.äöü', 'utf-8'), 123.345,
433-
decode('I am stdöüt!', 'utf-8'), decode('I am stdärr!', 'utf-8'))
448+
tc = TestCase(name=decode('Test äöü', 'utf-8'),
449+
classname=decode('some.class.name.äöü', 'utf-8'),
450+
elapsed_sec=123.345,
451+
stdout=decode('I am stdöüt!', 'utf-8'),
452+
stderr=decode('I am stdärr!', 'utf-8'))
434453
tc.add_skipped_info(message=decode('Skipped äöü', 'utf-8'),
435454
output=decode('I skippäd!', 'utf-8'))
436455
tc.add_error_info(message=decode('Skipped error äöü', 'utf-8'),
@@ -441,11 +460,12 @@ def test_init_unicode(self):
441460
verify_test_case(self, tcs[0], {'name': decode('Test äöü', 'utf-8'),
442461
'classname': decode('some.class.name.äöü', 'utf-8'),
443462
'time': ("%f" % 123.345)},
444-
stdout=decode('I am stdöüt!', 'utf-8'), stderr=decode('I am stdärr!', 'utf-8'),
445-
skipped_message=decode('Skipped äöü', 'utf-8'),
446-
skipped_output=decode('I skippäd!', 'utf-8'),
447-
error_message=decode('Skipped error äöü', 'utf-8'),
448-
error_output=decode('I skippäd with an error!', 'utf-8'))
463+
stdout=decode('I am stdöüt!', 'utf-8'),
464+
stderr=decode('I am stdärr!', 'utf-8'),
465+
skipped_message=decode('Skipped äöü', 'utf-8'),
466+
skipped_output=decode('I skippäd!', 'utf-8'),
467+
error_message=decode('Skipped error äöü', 'utf-8'),
468+
error_output=decode('I skippäd with an error!', 'utf-8'))
449469

450470

451471
def verify_test_case(tc, test_case_element, expected_attributes,

0 commit comments

Comments
 (0)