validate:launcher: Properly report stack trace as such in the xunit file

This commit is contained in:
Thibault Saunier 2016-11-26 10:24:11 -03:00
parent aec8693258
commit 03453961e8
2 changed files with 10 additions and 1 deletions

View file

@ -83,6 +83,7 @@ class Test(Loggable):
self.thread = None
self.queue = None
self.duration = duration
self.stack_trace = None
if expected_failures is None:
self.expected_failures = []
elif not isinstance(expected_failures, list):
@ -212,6 +213,8 @@ class Test(Loggable):
info = "\n\n== Stack trace: == \n%s" % stack_trace
if self.options.redirect_logs:
print(info)
elif self.options.xunit_file:
self.stack_trace = stack_trace
else:
with open(self.logfile, 'a') as f:
f.write(info)

View file

@ -202,15 +202,21 @@ class XunitReporter(Reporter):
"""
self.stats['failures'] += 1
stack_trace = ''
if test.stack_trace:
stack_trace = '<message><![CDATA[%s]]></message>\n' \
'<stack-trace><![CDATA[%s]]></stack-trace>' % (
self._quoteattr(test.message), escape_cdata(test.stack_trace))
xml_file = codecs.open(self.tmp_xml_file.name, 'a',
self.encoding, 'replace')
xml_file.write(self._forceUnicode(
'<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">'
'<failure type=%(errtype)s message=%(message)s>'
'<failure type=%(errtype)s message=%(message)s>%(stacktrace)s'
'</failure>%(systemout)s</testcase>' %
{'cls': self._quoteattr(test.get_classname()),
'name': self._quoteattr(test.get_name()),
'taken': test.time_taken,
'stacktrace': stack_trace,
'errtype': self._quoteattr(test.result),
'message': self._quoteattr(test.message),
'systemout': self._get_captured(test),