Anonymous avatar Anonymous committed 544160e

Applied xunit test name fix patch from issue 280. Closes issue 280.

Comments (0)

Files changed (4)

functional_tests/doc_tests/test_xunit_plugin/test_skips.rst

 FAILED (SKIP=1, errors=1, failures=1)
 
 >>> open(outfile, 'r').read() # doctest: +ELLIPSIS
-'<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="4" errors="1" failures="1" skip="1"><testcase classname="test_skip" name="test_skip.test_ok" time="..." /><testcase classname="test_skip" name="test_skip.test_err" time="..."><error type="exceptions.Exception">.../error></testcase><testcase classname="test_skip" name="test_skip.test_fail" time="..."><failure type="exceptions.AssertionError">...</failure></testcase></testsuite>'
+'<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="4" errors="1" failures="1" skip="1"><testcase classname="test_skip" name="test_ok" time="..." /><testcase classname="test_skip" name="test_err" time="..."><error type="exceptions.Exception">.../error></testcase><testcase classname="test_skip" name="test_fail" time="..."><failure type="exceptions.AssertionError">...</failure></testcase></testsuite>'

functional_tests/test_xunit.py

         
         assert '<?xml version="1.0" encoding="UTF-8"?>' in result
         assert '<testsuite name="nosetests" tests="5" errors="1" failures="1" skip="1">' in result
-        assert '<testcase classname="test_xunit_as_suite.TestForXunit" name="test_xunit_as_suite.TestForXunit.test_error" time="0">' in result
+        assert '<testcase classname="test_xunit_as_suite.TestForXunit" name="test_error" time="0">' in result
         assert '</testcase>' in result
         assert '</testsuite>' in result
 

nose/plugins/xunit.py

     <?xml version="1.0" encoding="UTF-8"?>
     <testsuite name="nosetests" tests="1" errors="1" failures="0" skip="0">
         <testcase classname="path_to_test_suite.TestSomething"
-                  name="path_to_test_suite.TestSomething.test_it" time="0">
+                  name="test_it" time="0">
             <error type="exceptions.TypeError">
             Traceback (most recent call last):
             ...
             '<testcase classname="%(cls)s" name="%(name)s" time="%(taken)d">'
             '<error type="%(errtype)s">%(tb)s</error></testcase>' %
             {'cls': self._xmlsafe('.'.join(id.split('.')[:-1])),
-             'name': self._xmlsafe(id),
+             'name': self._xmlsafe(id.split('.')[-1]),
              'errtype': self._xmlsafe(nice_classname(err[0])),
              'tb': self._xmlsafe(tb),
              'taken': taken,
             '<testcase classname="%(cls)s" name="%(name)s" time="%(taken)d">'
             '<failure type="%(errtype)s">%(tb)s</failure></testcase>' %
             {'cls': self._xmlsafe('.'.join(id.split('.')[:-1])),
-             'name': self._xmlsafe(id),
+             'name': self._xmlsafe(id.split('.')[-1]),
              'errtype': self._xmlsafe(nice_classname(err[0])),
              'tb': self._xmlsafe(tb),
              'taken': taken,
             '<testcase classname="%(cls)s" name="%(name)s" '
             'time="%(taken)d" />' %
             {'cls': self._xmlsafe('.'.join(id.split('.')[:-1])),
-             'name': self._xmlsafe(id),
+             'name': self._xmlsafe(id.split('.')[-1]),
              'taken': taken,
              })

unit_tests/test_xunit.py

 from nose.exc import SkipTest
 from nose.config import Config
 
-def mktest():    
+def mktest():
     class TC(unittest.TestCase):
         def runTest(self):
             pass
 mktest.__test__ = False
 
 class TestEscaping(unittest.TestCase):
-    
+
     def setUp(self):
         self.x = Xunit()
-    
+
     def test_all(self):
         eq_(self.x._xmlsafe(
             '''<baz src="http://foo?f=1&b=2" quote="inix hubris 'maximus'?" />'''),
             ('&lt;baz src=&quot;http://foo?f=1&amp;b=2&quot; '
                 'quote=&quot;inix hubris &#39;maximus&#39;?&quot; /&gt;'))
 
-    
+
     def test_unicode_is_utf8_by_default(self):
         eq_(self.x._xmlsafe(u'Ivan Krsti\u0107'),
             'Ivan Krsti\xc4\x87')
 
-    
+
     def test_unicode_custom_utf16_madness(self):
         self.x.encoding = 'utf-16'
         utf16 = self.x._xmlsafe(u'Ivan Krsti\u0107')
-        
+
         # to avoid big/little endian bytes, assert that we can put it back:
         eq_(utf16.decode('utf16'), u'Ivan Krsti\u0107')
 
 class TestOptions(unittest.TestCase):
-    
+
     def test_defaults(self):
         parser = optparse.OptionParser()
         x = Xunit()
         x.add_options(parser, env={})
         (options, args) = parser.parse_args([])
         eq_(options.xunit_file, "nosetests.xml")
-    
+
     def test_file_from_environ(self):
         parser = optparse.OptionParser()
         x = Xunit()
         x.add_options(parser, env={'NOSE_XUNIT_FILE': "kangaroo.xml"})
         (options, args) = parser.parse_args([])
         eq_(options.xunit_file, "kangaroo.xml")
-    
+
     def test_file_from_opt(self):
         parser = optparse.OptionParser()
         x = Xunit()
         x.add_options(parser, env={})
         (options, args) = parser.parse_args(["--xunit-file=blagojevich.xml"])
         eq_(options.xunit_file, "blagojevich.xml")
-    
+
 class TestXMLOutputWithXML(unittest.TestCase):
-    
+
     def setUp(self):
         self.xmlfile = os.path.abspath(
             os.path.join(os.path.dirname(__file__), 
             "--xunit-file=%s" % self.xmlfile
         ])
         self.x.configure(options, Config())
-        
+
         try:
             import xml.etree.ElementTree
         except ImportError:
             self.ET = False
         else:
             self.ET = xml.etree.ElementTree
-    
+
     def tearDown(self):
         os.unlink(self.xmlfile)
-    
+
     def get_xml_report(self):
         class DummyStream:
             pass
         
             tc = tree.find("testcase")
             eq_(tc.attrib['classname'], "test_xunit.TC")
-            eq_(tc.attrib['name'], "test_xunit.TC.runTest")
+            eq_(tc.attrib['name'], "runTest")
             assert int(tc.attrib['time']) >= 0
         
             err = tc.find("failure")
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert '<testsuite name="nosetests" tests="1" errors="0" failures="1" skip="0">' in result
-            assert '<testcase classname="test_xunit.TC" name="test_xunit.TC.runTest"' in result
+            assert '<testcase classname="test_xunit.TC" name="runTest"' in result
             assert '<failure type="exceptions.AssertionError">' in result
             assert 'AssertionError: one is not &#39;equal&#39; to two' in result
             assert 'AssertionError(&quot;one is not &#39;equal&#39; to two&quot;)' in result
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert ('<testcase classname="test_xunit.TC" '
-                    'name="test_xunit.TC.runTest" time="0">') in result
+                    'name="runTest" time="0">') in result
     
     def test_addError(self):
         test = mktest()
         
             tc = tree.find("testcase")
             eq_(tc.attrib['classname'], "test_xunit.TC")
-            eq_(tc.attrib['name'], "test_xunit.TC.runTest")
+            eq_(tc.attrib['name'], "runTest")
             assert int(tc.attrib['time']) >= 0
         
             err = tc.find("error")
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert '<testsuite name="nosetests" tests="1" errors="1" failures="0" skip="0">' in result
-            assert '<testcase classname="test_xunit.TC" name="test_xunit.TC.runTest"' in result
+            assert '<testcase classname="test_xunit.TC" name="runTest"' in result
             assert '<error type="exceptions.RuntimeError">' in result
             assert 'RuntimeError: some error happened' in result
             assert '</error></testcase></testsuite>' in result
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert ('<testcase classname="test_xunit.TC" '
-                    'name="test_xunit.TC.runTest" time="0">') in result
+                    'name="runTest" time="0">') in result
         
     def test_addSuccess(self):
         test = mktest()
         
             tc = tree.find("testcase")
             eq_(tc.attrib['classname'], "test_xunit.TC")
-            eq_(tc.attrib['name'], "test_xunit.TC.runTest")
+            eq_(tc.attrib['name'], "runTest")
             assert int(tc.attrib['time']) >= 0
         else:
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert '<testsuite name="nosetests" tests="1" errors="0" failures="0" skip="0">' in result
-            assert '<testcase classname="test_xunit.TC" name="test_xunit.TC.runTest"' in result
+            assert '<testcase classname="test_xunit.TC" name="runTest"' in result
             assert '</testsuite>' in result
     
     def test_addSuccess_early(self):
             # this is a dumb test for 2.4-
             assert '<?xml version="1.0" encoding="UTF-8"?>' in result
             assert ('<testcase classname="test_xunit.TC" '
-                    'name="test_xunit.TC.runTest" time="0" />') in result
+                    'name="runTest" time="0" />') in result
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.