Skip to content

Commit

Permalink
Merge pull request nose-devs#862 from Gaurang033/master
Browse files Browse the repository at this point in the history
Fix nose-devs#859 Xunit plug-in not able to change testsuite name
  • Loading branch information
jszakmeister committed Dec 19, 2014
2 parents 347352a + 3f930d7 commit e2b1749
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions functional_tests/support/issue859/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from unittest import TestCase


class TestBase(TestCase):
def test_a(self):
assert 1 == 1
17 changes: 17 additions & 0 deletions functional_tests/test_xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions nose/plugins/xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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'<?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)
Expand Down

0 comments on commit e2b1749

Please sign in to comment.