summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Szakmeister <john@szakmeister.net>2014-12-19 05:13:08 -0500
committerJohn Szakmeister <john@szakmeister.net>2014-12-19 05:13:08 -0500
commite2b1749024d26bb2b5f7c4644dca57b6e899600a (patch)
tree57c28313d9d491e546479146c5f3eec17ebc8c16
parent347352af79dfced2827266986a22c0259e1a8012 (diff)
parent3f930d734237a7b6b68b1b7dadb12fa25458bd49 (diff)
downloadnose-e2b1749024d26bb2b5f7c4644dca57b6e899600a.tar.gz
Merge pull request #862 from Gaurang033/master
Fix #859 Xunit plug-in not able to change testsuite name
-rw-r--r--functional_tests/support/issue859/test.py6
-rw-r--r--functional_tests/test_xunit.py17
-rw-r--r--nose/plugins/xunit.py16
3 files changed, 37 insertions, 2 deletions
diff --git a/functional_tests/support/issue859/test.py b/functional_tests/support/issue859/test.py
new file mode 100644
index 0000000..7871f2c
--- /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 9f4ac2f..6c2e99d 100644
--- a/functional_tests/test_xunit.py
+++ b/functional_tests/test_xunit.py
@@ -108,3 +108,20 @@ class TestIssue700(PluginTester, unittest.TestCase):
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 e1ec0e1..90b52f5 100644
--- a/nose/plugins/xunit.py
+++ b/nose/plugins/xunit.py
@@ -19,6 +19,9 @@ under the Post-build Actions and enter this value for Test report XMLs::
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::
<?xml version="1.0" encoding="UTF-8"?>
@@ -155,7 +158,7 @@ class Xunit(Plugin):
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 @@ class Xunit(Plugin):
"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 @@ class Xunit(Plugin):
}
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 @@ class Xunit(Plugin):
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'<?xml version="1.0" encoding="%(encoding)s"?>'
- u'<testsuite name="nosetests" tests="%(total)d" '
+ u'<testsuite name="%(testsuite_name)s" tests="%(total)d" '
u'errors="%(errors)d" failures="%(failures)d" '
u'skip="%(skipped)d">' % self.stats)
self.error_report_file.write(u''.join([force_unicode(e, self.encoding)