summaryrefslogtreecommitdiff
path: root/nose/plugins/xunit.py
diff options
context:
space:
mode:
Diffstat (limited to 'nose/plugins/xunit.py')
-rw-r--r--nose/plugins/xunit.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/nose/plugins/xunit.py b/nose/plugins/xunit.py
index b43ff04..77e68e3 100644
--- a/nose/plugins/xunit.py
+++ b/nose/plugins/xunit.py
@@ -22,6 +22,12 @@ If you need to change the name or location of the file, you can set the
If you need to change the name of the test suite, you can set the
``--xunit-testsuite-name`` option.
+If you need to prefix the name of the tested classes, you can set the
+``--xunit-prefix-with-testsuite-name`` option.
+This can be used in a matrixed build to distinguish between failures
+in different environments.
+The testsuite name is used as a prefix.
+
Here is an abbreviated version of what an XML test report might look like::
<?xml version="1.0" encoding="UTF-8"?>
@@ -169,6 +175,12 @@ class Xunit(Plugin):
attr = xml_safe(attr)
return saxutils.quoteattr(attr)
+ def _getCls(self, id):
+ if self.xunit_prefix_class:
+ return self._quoteattr('%s.%s' % (self.xunit_testsuite_name, id_split(id)[0]))
+ else:
+ return self._quoteattr(id_split(id)[0])
+
def options(self, parser, env):
"""Sets additional command line options."""
Plugin.options(self, parser, env)
@@ -187,6 +199,13 @@ class Xunit(Plugin):
help=("Name of the testsuite in the xunit xml, generated by plugin. "
"Default test suite name is nosetests."))
+ parser.add_option(
+ '--xunit-prefix-with-testsuite-name', action='store_true',
+ dest='xunit_prefix_class',
+ default=bool(env.get('NOSE_XUNIT_PREFIX_WITH_TESTSUITE_NAME', False)),
+ help=("Whether to prefix the class name under test with testsuite name. "
+ "Defaults to false."))
+
def configure(self, options, config):
"""Configures the xunit plugin."""
Plugin.configure(self, options, config)
@@ -200,6 +219,7 @@ class Xunit(Plugin):
self.errorlist = []
self.error_report_file_name = os.path.realpath(options.xunit_file)
self.xunit_testsuite_name = options.xunit_testsuite_name
+ self.xunit_prefix_class = options.xunit_prefix_class
def report(self, stream):
"""Writes an Xunit-formatted XML file
@@ -292,7 +312,7 @@ class Xunit(Plugin):
u'<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">'
u'<%(type)s type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]>'
u'</%(type)s>%(systemout)s%(systemerr)s</testcase>' %
- {'cls': self._quoteattr(id_split(id)[0]),
+ {'cls': self._getCls(id),
'name': self._quoteattr(id_split(id)[-1]),
'taken': taken,
'type': type,
@@ -315,7 +335,7 @@ class Xunit(Plugin):
u'<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">'
u'<failure type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]>'
u'</failure>%(systemout)s%(systemerr)s</testcase>' %
- {'cls': self._quoteattr(id_split(id)[0]),
+ {'cls': self._getCls(id),
'name': self._quoteattr(id_split(id)[-1]),
'taken': taken,
'errtype': self._quoteattr(nice_classname(err[0])),
@@ -334,7 +354,7 @@ class Xunit(Plugin):
self.errorlist.append(
'<testcase classname=%(cls)s name=%(name)s '
'time="%(taken).3f">%(systemout)s%(systemerr)s</testcase>' %
- {'cls': self._quoteattr(id_split(id)[0]),
+ {'cls': self._getCls(id),
'name': self._quoteattr(id_split(id)[-1]),
'taken': taken,
'systemout': self._getCapturedStdout(),