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

This commit is contained in:
holger krekel 2012-11-03 20:54:48 +01:00
parent ba9b27fcd3
commit 7e831b66ec
3 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,8 @@ Changes between 2.3.2 and 2.3.3.dev
- 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
-----------------------------------

View File

@ -46,12 +46,16 @@ class UnitTestCase(pytest.Class):
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()

View File

@ -96,6 +96,25 @@ def test_teardown(testdir):
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