Commit 95d2f280 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Add fixup for nosetests XML output.

The XML output for nosetests does not separate the test module from
the class. A fixup hasa been added to try to make these results more
useful.
parent c29d75a1
...@@ -334,7 +334,9 @@ function merge_test_results() { ...@@ -334,7 +334,9 @@ function merge_test_results() {
echo "No JUnit XML files generated" echo "No JUnit XML files generated"
else else
echo "Merging ${#test_files[@]} files into '${artifact_dir}/test-results.xml'" echo "Merging ${#test_files[@]} files into '${artifact_dir}/test-results.xml'"
"${scripts}/junit-xml" --output "${artifact_dir}/test-results.xml" "${test_files[@]}" "${scripts}/junit-xml" --fix-nosetests \
--output "${artifact_dir}/test-results.xml" \
"${test_files[@]}"
fi fi
# And clear up the files that we now no-longer need. # And clear up the files that we now no-longer need.
......
...@@ -251,6 +251,42 @@ class TestSuite(object): ...@@ -251,6 +251,42 @@ class TestSuite(object):
return suite return suite
def fix_nosetests(txml):
"""
The 'nosetests' tool writes out a file with the 'testsuite.name' set to 'nosetests',
and the 'testcase.classname' set to '<package>.<class>'. This function attempts to
fix up such cases, so that 'testsuite.name' is the package, and 'testcase.classname'
is the class alone.
"""
for suite in txml.suites:
if suite.name == 'nosetests':
# The fix could be applied.
name_is_common = None
test_package = None
for case in suite.testcases:
# at present the testcases are actually still XML Nodes.
classname = case.attrib.get('classname', None)
if classname and '.' in classname:
tname, cname = classname.split('.', 1)
if not test_package:
test_package = tname
name_is_common = True
else:
if test_package != tname:
name_is_common = False
break
if name_is_common:
# We can make the replacement.
for case in suite.testcases:
classname = case.attrib.get('classname', None)
if classname and '.' in classname:
tname, cname = classname.split('.', 1)
case.attrib['classname'] = cname
suite.name = test_package
def main(): def main():
usage = "junit-xml <options> {<junit-files>}*" usage = "junit-xml <options> {<junit-files>}*"
parser = argparse.ArgumentParser(usage=usage, parser = argparse.ArgumentParser(usage=usage,
...@@ -258,6 +294,8 @@ def main(): ...@@ -258,6 +294,8 @@ def main():
parser.add_argument('--output', type=str, parser.add_argument('--output', type=str,
help="Specify the JUnit output file", default='test-results.xml') help="Specify the JUnit output file", default='test-results.xml')
parser.add_argument('--fix-nosetests',
help="Move the package name to the test suite", default=False, action='store_true')
parser.add_argument('files', nargs='+', parser.add_argument('files', nargs='+',
help='JUnit files to merge together') help='JUnit files to merge together')
...@@ -267,6 +305,9 @@ def main(): ...@@ -267,6 +305,9 @@ def main():
for xmlfile in options.files: for xmlfile in options.files:
txml += TestXML(xmlfile) txml += TestXML(xmlfile)
if options.fix_nosetests:
fix_nosetests(txml)
xml = txml.xml() xml = txml.xml()
xml.write(options.output, encoding='UTF-8', xml_declaration=True) xml.write(options.output, encoding='UTF-8', xml_declaration=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment