Bug 813779 - Make Marionette's xunit output compatible with Jenkins, r=dhunt

This commit is contained in:
Jonathan Griffin 2012-11-26 15:53:41 -08:00
parent f245d05c08
commit f9938b0247
2 changed files with 32 additions and 54 deletions

View File

@ -482,92 +482,70 @@ class MarionetteTestRunner(object):
def generate_xml(self, results_list):
def _extract_xml(test, text='', result='Pass'):
def _extract_xml(test, text='', result='passed'):
cls_name = test.__class__.__name__
# if the test class is not already created, create it
if cls_name not in classes:
cls = doc.createElement('class')
cls.setAttribute('name', cls_name)
assembly.appendChild(cls)
classes[cls_name] = cls
testcase = doc.createElement('testcase')
testcase.setAttribute('classname', cls_name)
testcase.setAttribute('name', unicode(test).split()[0])
testsuite.appendChild(testcase)
t = doc.createElement('test')
t.setAttribute('name', unicode(test).split()[0])
t.setAttribute('result', result)
if result == 'Fail':
f = doc.createElement('failure')
st = doc.createElement('stack-trace')
st.appendChild(doc.createTextNode(text))
f.appendChild(st)
t.appendChild(f)
elif result == 'Skip':
r = doc.createElement('reason')
msg = doc.createElement('message')
msg.appendChild(doc.createTextNode(text))
r.appendChild(msg)
t.appendChild(r)
cls = classes[cls_name]
cls.appendChild(t)
if result in ['failure', 'error', 'skipped']:
f = doc.createElement(result)
f.setAttribute('message', 'test %s' % result)
f.appendChild(doc.createTextNode(text))
testcase.appendChild(f)
doc = dom.Document()
assembly = doc.createElement('assembly')
assembly.setAttribute('name', 'Tests')
assembly.setAttribute('time', str(self.elapsedtime))
assembly.setAttribute('total', str(sum([results.testsRun for
results in results_list])))
assembly.setAttribute('passed', str(sum([results.passed for
results in results_list])))
testsuite = doc.createElement('testsuite')
testsuite.setAttribute('name', 'Marionette')
# convert elapsedtime to integer milliseconds
testsuite.setAttribute('time', str(int(self.elapsedtime.total_seconds() * 1000)))
testsuite.setAttribute('tests', str(sum([results.testsRun for
results in results_list])))
def failed_count(results):
count = len(results.failures) + len(results.errors)
count = len(results.failures)
if hasattr(results, 'unexpectedSuccesses'):
count += len(results.unexpectedSuccesses)
return count
assembly.setAttribute('failed', str(sum([failed_count(results)
for results in results_list])))
testsuite.setAttribute('failures', str(sum([failed_count(results)
for results in results_list])))
testsuite.setAttribute('errors', str(sum([len(results.errors)
for results in results_list])))
if hasattr(results, 'skipped'):
assembly.setAttribute('skipped', str(sum([len(results.skipped) +
len(results.expectedFailures)
for results in results_list])))
testsuite.setAttribute('skips', str(sum([len(results.skipped) +
len(results.expectedFailures)
for results in results_list])))
for results in results_list:
classes = {} # str -> xml class element
for tup in results.errors:
_extract_xml(*tup, result='Fail')
_extract_xml(*tup, result='error')
for tup in results.failures:
_extract_xml(*tup, result='Fail')
_extract_xml(*tup, result='failure')
if hasattr(results, 'unexpectedSuccesses'):
for test in results.unexpectedSuccesses:
# unexpectedSuccesses is a list of Testcases only, no tuples
_extract_xml(test, text='TEST-UNEXPECTED-PASS', result='Fail')
_extract_xml(test, text='TEST-UNEXPECTED-PASS', result='failure')
if hasattr(results, 'skipped'):
for tup in results.skipped:
_extract_xml(*tup, result='Skip')
_extract_xml(*tup, result='skipped')
if hasattr(results, 'expectedFailures'):
for tup in results.expectedFailures:
_extract_xml(*tup, result='Skip')
_extract_xml(*tup, result='skipped')
for test in results.tests_passed:
_extract_xml(test)
for cls in classes.itervalues():
assembly.appendChild(cls)
doc.appendChild(assembly)
return doc.toxml(encoding='utf-8')
doc.appendChild(testsuite)
return doc.toprettyxml(encoding='utf-8')
def parse_options():

View File

@ -1,7 +1,7 @@
import os
from setuptools import setup, find_packages
version = '0.5.8'
version = '0.5.9'
# get documentation from the README
try: