diff --git a/functional_tests/support/issue859/test.py b/functional_tests/support/issue859/test.py new file mode 100644 index 00000000..7871f2c2 --- /dev/null +++ b/functional_tests/support/issue859/test.py @@ -0,0 +1,6 @@ +from unittest import TestCase + + +class TestBase(TestCase): + def test_a(self): + assert 1 == 1 diff --git a/functional_tests/test_xunit.py b/functional_tests/test_xunit.py index 9f4ac2fa..6c2e99d7 100644 --- a/functional_tests/test_xunit.py +++ b/functional_tests/test_xunit.py @@ -108,3 +108,20 @@ def runTest(self): assert 'tests="1" errors="0" failures="0" skip="0"' in result assert 'line1\n' in result assert 'line2\n' in result + + +class TestIssue859(PluginTester, unittest.TestCase): + activate = '--with-xunit' + testsuite_name = "TestIssue859" + args = ['-v', '--xunit-file=%s' % xml_results_filename, '--xunit-testsuite-name=%s' % testsuite_name] + plugins = [Xunit(), Skip()] + suitepath = os.path.join(support, 'issue859') + + def runTest(self): + print str(self.output) + f = open(xml_results_filename, 'r') + result = f.read() + f.close() + print result + assert 'tests="1" errors="0" failures="0" skip="0"' in result + assert 'testsuite name="TestIssue859"' in result diff --git a/nose/plugins/xunit.py b/nose/plugins/xunit.py index e1ec0e1d..90b52f5f 100644 --- a/nose/plugins/xunit.py +++ b/nose/plugins/xunit.py @@ -19,6 +19,9 @@ If you need to change the name or location of the file, you can set the ``--xunit-file`` option. +If you need to change the name of the test suite, you can set the +``--xunit-testsuite-name`` option. + Here is an abbreviated version of what an XML test report might look like:: @@ -155,7 +158,7 @@ def _timeTaken(self): taken = time() - self._timer else: # test died before it ran (probably error in setup()) - # or success/failure added before test started probably + # or success/failure added before test started probably # due to custom TestResult munging taken = 0.0 return taken @@ -176,6 +179,13 @@ def options(self, parser, env): "Default is nosetests.xml in the working directory " "[NOSE_XUNIT_FILE]")) + parser.add_option( + '--xunit-testsuite-name', action='store', + dest='xunit_testsuite_name', metavar="PACKAGE", + default=env.get('NOSE_XUNIT_TESTSUITE_NAME', 'nosetests'), + help=("Name of the testsuite in the xunit xml, generated by plugin. " + "Default test suite name is nosetests.")) + def configure(self, options, config): """Configures the xunit plugin.""" Plugin.configure(self, options, config) @@ -188,6 +198,7 @@ def configure(self, options, config): } self.errorlist = [] self.error_report_file_name = os.path.realpath(options.xunit_file) + self.xunit_testsuite_name = options.xunit_testsuite_name def report(self, stream): """Writes an Xunit-formatted XML file @@ -198,11 +209,12 @@ def report(self, stream): self.error_report_file = codecs.open(self.error_report_file_name, 'w', self.encoding, 'replace') self.stats['encoding'] = self.encoding + self.stats['testsuite_name'] = self.xunit_testsuite_name self.stats['total'] = (self.stats['errors'] + self.stats['failures'] + self.stats['passes'] + self.stats['skipped']) self.error_report_file.write( u'' - u'' % self.stats) self.error_report_file.write(u''.join([force_unicode(e, self.encoding)