diff --git a/CHANGELOG b/CHANGELOG index 1e18f9684..5aa848852 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -31,6 +31,7 @@ Changes between 2.1.3 and 2.2.0 - fix compatibility with twisted/trial-11.1.0 use cases - simplify Node.listchain - simplify junitxml output code by relying on py.xml +- add support for skip properties on unittest classes and functions Changes between 2.1.2 and 2.1.3 ---------------------------------------- diff --git a/_pytest/unittest.py b/_pytest/unittest.py index 324dab048..2f04f334d 100644 --- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -46,6 +46,10 @@ class TestCaseFunction(pytest.Function): def setup(self): self._testcase = self.parent.obj(self.name) self._obj = getattr(self._testcase, self.name) + if hasattr(self._testcase, 'skip'): + pytest.skip(self._testcase.skip) + if hasattr(self._obj, 'skip'): + pytest.skip(self._obj.skip) if hasattr(self._testcase, 'setup_method'): self._testcase.setup_method(self._obj) diff --git a/testing/test_unittest.py b/testing/test_unittest.py index a0bfe5c78..738408f96 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -232,6 +232,29 @@ def test_module_level_pytestmark(testdir): reprec.assertoutcome(skipped=1) +def test_testcase_skip_property(testdir): + testpath = testdir.makepyfile(""" + import unittest + class MyTestCase(unittest.TestCase): + skip = 'dont run' + def test_func(self): + pass + """) + reprec = testdir.inline_run(testpath, "-s") + reprec.assertoutcome(skipped=1) + +def test_testfunction_skip_property(testdir): + testpath = testdir.makepyfile(""" + import unittest + class MyTestCase(unittest.TestCase): + def test_func(self): + pass + test_func.skip = 'dont run' + """) + reprec = testdir.inline_run(testpath, "-s") + reprec.assertoutcome(skipped=1) + + class TestTrialUnittest: def setup_class(cls): pytest.importorskip("twisted.trial.unittest")