Created
April 7, 2010 23:52
-
-
Save admc/359594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functest | |
from functest import reports | |
from xml.etree import ElementTree | |
class JUnitReporter(reports.FunctestReportInterface): | |
def summary(self, test_list, totals_dict, stdout_capture): | |
if functest.registry.get('report', False): | |
total_sec = reduce(lambda x, y: (y.endtime - y.starttime).seconds + x, test_list, 0) | |
e = ElementTree.Element('testsuite') | |
e.attrib['errors'] = e.attrib['failures'] = str(totals_dict['fail']) | |
e.attrib['tests'] = str(len(test_list)) | |
e.attrib['name'] = 'windmill.functional' | |
e.attrib['time'] = str(total_sec) | |
for entry in test_list: | |
t = entry.endtime - entry.starttime | |
test = ElementTree.Element('testcase') | |
test.attrib['classname'] = test.attrib['name'] = entry.__name__ | |
test.attrib['time'] = str(t.seconds)+'.'+str(t.microseconds) | |
if entry.result is not True: | |
failure = ElementTree.Element('failure') | |
failure.attrib['type'] = entry.tb[-1].split(':')[0] | |
failure.text = '\n'.join(entry.tb) | |
test.append(failure) | |
e.append(test) | |
if len(stdout_capture): | |
# ElementTree doesn't support CDATA so we need to hack it a little | |
replace = '#$!#$!replace#@!$' | |
sysout = ElementTree.Element('system-out') | |
sysout.text = replace | |
e.append(sysout) | |
outs = ElementTree.tostring(e).replace(replace, '<!--[CDATA['+stdout_capture+']]-->') | |
else: | |
outs = ElementTree.tostring(e) | |
f = open('continuous_test.log','w') | |
f.write(outs) ; f.close() | |
reports.register_reporter(JUnitReporter()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment