From 7e831b66ec0b402751c9cc7d65d80c67dc52640a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 3 Nov 2012 20:54:48 +0100 Subject: [PATCH] fix issue148 - recognize @unittest.skip on classes, avoid setup/teardown --- CHANGELOG | 2 ++ _pytest/unittest.py | 4 ++++ testing/test_unittest.py | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 56ce8a1cd..8470e9afd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ----------------------------------- diff --git a/_pytest/unittest.py b/_pytest/unittest.py index c77b02736..61c896404 100644 --- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -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() diff --git a/testing/test_unittest.py b/testing/test_unittest.py index c62277a83..eecc9da68 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -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