Commits

holger krekel committed dd4b2fd

fix issue148 - recognize @unittest.skip on classes, avoid setup/teardown

Comments (0)

Files changed (3)

 
 - fix issue215 - split test_python.org into multiple files
 
+- fix issue148 - @unittest.skip on classes is now recognized and avoids
+  calling setUpClass/tearDownClass
 
 Changes between 2.3.1 and 2.3.2
 -----------------------------------

_pytest/unittest.py

                     yield TestCaseFunction('runTest', parent=self)
 
     def setup(self):
+        if getattr(self.obj, '__unittest_skip__', False):
+            return
         meth = getattr(self.obj, 'setUpClass', None)
         if meth is not None:
             meth()
         super(UnitTestCase, self).setup()
 
     def teardown(self):
+        if getattr(self.obj, '__unittest_skip__', False):
+            return
         meth = getattr(self.obj, 'tearDownClass', None)
         if meth is not None:
             meth()

testing/test_unittest.py

     assert passed == 2
     assert passed + skipped + failed == 2
 
+@pytest.mark.skipif("sys.version_info < (3,1)")
+def test_unittest_skip_issue148(testdir):
+    testpath = testdir.makepyfile("""
+        import unittest
+
+        @unittest.skip("hello")
+        class MyTestCase(unittest.TestCase):
+            @classmethod
+            def setUpClass(self):
+                xxx
+            def test_one(self):
+                pass
+            @classmethod
+            def tearDownClass(self):
+                xxx
+    """)
+    reprec = testdir.inline_run(testpath)
+    reprec.assertoutcome(skipped=1)
+
 def test_method_and_teardown_failing_reporting(testdir):
     testdir.makepyfile("""
         import unittest, pytest