diff options
author | Joscha Feth <joscha@feth.com> | 2015-11-12 18:14:54 +1100 |
---|---|---|
committer | Joscha Feth <joscha@feth.com> | 2015-11-29 00:12:54 +1100 |
commit | 062b73ee728790b5f551ebfbf4dba14845fbec57 (patch) | |
tree | dd998a131bd05050d155aff1707f2a6bfa876460 /unit_tests | |
parent | fb4a919f171a80c3381a6408ac16508d91d94a26 (diff) | |
download | nose-062b73ee728790b5f551ebfbf4dba14845fbec57.tar.gz |
feat: adds an option that allows prefixing the class name in an xunit report
Diffstat (limited to 'unit_tests')
-rw-r--r-- | unit_tests/test_xunit.py | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/unit_tests/test_xunit.py b/unit_tests/test_xunit.py index dd54b8d..dc25599 100644 --- a/unit_tests/test_xunit.py +++ b/unit_tests/test_xunit.py @@ -95,19 +95,32 @@ class TestTee(unittest.TestCase): class TestXMLOutputWithXML(unittest.TestCase): + def test_prefix_from_environ(self): + parser = optparse.OptionParser() + x = Xunit() + x.add_options(parser, env={'NOSE_XUNIT_PREFIX_WITH_TESTSUITE_NAME': 'true'}) + (options, args) = parser.parse_args([]) + eq_(options.xunit_prefix_class, True) + + def test_prefix_from_opt(self): + parser = optparse.OptionParser() + x = Xunit() + x.add_options(parser, env={}) + (options, args) = parser.parse_args(["--xunit-prefix-with-testsuite-name"]) + eq_(options.xunit_prefix_class, True) + +class BaseTestXMLOutputWithXML(unittest.TestCase): + def configure(self, args): + parser = optparse.OptionParser() + self.x.add_options(parser, env={}) + (options, args) = parser.parse_args(args) + self.x.configure(options, Config()) def setUp(self): self.xmlfile = os.path.abspath( os.path.join(os.path.dirname(__file__), 'support', 'xunit.xml')) - parser = optparse.OptionParser() self.x = Xunit() - self.x.add_options(parser, env={}) - (options, args) = parser.parse_args([ - "--with-xunit", - "--xunit-file=%s" % self.xmlfile - ]) - self.x.configure(options, Config()) try: import xml.etree.ElementTree @@ -128,6 +141,39 @@ class TestXMLOutputWithXML(unittest.TestCase): f.close() return data +class TestXMLOutputWithXMLAndPrefix(BaseTestXMLOutputWithXML): + def setUp(self): + super(TestXMLOutputWithXMLAndPrefix, self).setUp() + self.configure([ + "--with-xunit", + "--xunit-file=%s" % self.xmlfile, + "--xunit-prefix-with-testsuite-name" + ]) + + def test_addSuccess(self): + test = mktest() + self.x.beforeTest(test) + self.x.addSuccess(test, (None,None,None)) + + result = self.get_xml_report() + print result + + if self.ET: + tree = self.ET.fromstring(result) + tc = tree.find("testcase") + eq_(tc.attrib['classname'], "nosetests.test_xunit.TC") + else: + # this is a dumb test for 2.4- + assert '<testcase classname="nosetests.test_xunit.TC" name="runTest"' in result + +class TestXMLOutputWithXML(BaseTestXMLOutputWithXML): + def setUp(self): + super(TestXMLOutputWithXML, self).setUp() + self.configure([ + "--with-xunit", + "--xunit-file=%s" % self.xmlfile + ]) + def test_addFailure(self): test = mktest() self.x.beforeTest(test) |