From 4656bc4c97ad9c143219e331331d085bc32cb48d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 30 Dec 2009 12:13:38 +0100 Subject: [PATCH] deprecate use of 'disabled' --HG-- branch : trunk --- CHANGELOG | 2 ++ py/impl/test/pycollect.py | 4 +++ py/plugin/pytest_recwarn.py | 1 + testing/pytest/test_deprecated_api.py | 43 +++++++++++++++++++++++++++ testing/pytest/test_pycollect.py | 39 ------------------------ 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 454ad3d1e..886922c4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,8 @@ Changes between 1.X and 1.1.1 - allow pytest_generate_tests to be defined in classes as well +- deprecate usage of 'disabled' attribute in favour of pytestmark + - collection/item node specific runtest/collect hooks are only called exactly on matching conftest.py files, i.e. ones which are exactly below the filesystem path of an item diff --git a/py/impl/test/pycollect.py b/py/impl/test/pycollect.py index 48f99b6e5..3802cfaa8 100644 --- a/py/impl/test/pycollect.py +++ b/py/impl/test/pycollect.py @@ -167,6 +167,8 @@ class Module(py.test.collect.File, PyCollectorMixin): def setup(self): if getattr(self.obj, 'disabled', 0): + py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, " + "use pytestmark=..., see pytest_skipping plugin" % (self.obj,)) py.test.skip("%r is disabled" %(self.obj,)) if hasattr(self.obj, 'setup_module'): #XXX: nose compat hack, move to nose plugin @@ -197,6 +199,8 @@ class Class(PyCollectorMixin, py.test.collect.Collector): def setup(self): if getattr(self.obj, 'disabled', 0): + py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, " + "use pytestmark=..., see pytest_skipping plugin" % (self.obj,)) py.test.skip("%r is disabled" %(self.obj,)) setup_class = getattr(self.obj, 'setup_class', None) if setup_class is not None: diff --git a/py/plugin/pytest_recwarn.py b/py/plugin/pytest_recwarn.py index 022ff711d..4bfc57cdd 100644 --- a/py/plugin/pytest_recwarn.py +++ b/py/plugin/pytest_recwarn.py @@ -72,6 +72,7 @@ def deprecated_call(func, *args, **kwargs): warningmodule.warn = warn if not l: #print warningmodule + __tracebackhide__ = True raise AssertionError("%r did not produce DeprecationWarning" %(func,)) return ret diff --git a/testing/pytest/test_deprecated_api.py b/testing/pytest/test_deprecated_api.py index d217c4c29..71e9c6937 100644 --- a/testing/pytest/test_deprecated_api.py +++ b/testing/pytest/test_deprecated_api.py @@ -1,5 +1,6 @@ import py +from py.impl.test.outcome import Skipped class TestCollectDeprecated: @@ -167,3 +168,45 @@ class TestCollectDeprecated: config = testdir.parseconfig(testme) col = config.getfsnode(testme) assert col.collect() == [] + + +class TestDisabled: + def test_disabled_module(self, recwarn, testdir): + modcol = testdir.getmodulecol(""" + disabled = True + def setup_module(mod): + raise ValueError + def test_method(): + pass + """) + l = modcol.collect() + assert len(l) == 1 + recwarn.clear() + py.test.raises(Skipped, "modcol.setup()") + recwarn.pop(DeprecationWarning) + + def test_disabled_class(self, recwarn, testdir): + modcol = testdir.getmodulecol(""" + class TestClass: + disabled = True + def test_method(self): + pass + """) + l = modcol.collect() + assert len(l) == 1 + modcol = l[0] + assert isinstance(modcol, py.test.collect.Class) + l = modcol.collect() + assert len(l) == 1 + recwarn.clear() + py.test.raises(Skipped, "modcol.setup()") + recwarn.pop(DeprecationWarning) + + def test_disabled_class_functional(self, testdir): + reprec = testdir.inline_runsource(""" + class TestSimpleClassSetup: + disabled = True + def test_classlevel(self): pass + def test_classlevel2(self): pass + """) + reprec.assertoutcome(skipped=2) diff --git a/testing/pytest/test_pycollect.py b/testing/pytest/test_pycollect.py index a0cbdb2f8..231d1519a 100644 --- a/testing/pytest/test_pycollect.py +++ b/testing/pytest/test_pycollect.py @@ -1,7 +1,5 @@ import py -from py.impl.test.outcome import Skipped - class TestModule: def test_module_file_not_found(self, testdir): tmpdir = testdir.tmpdir @@ -50,43 +48,6 @@ class TestClass: """) l = modcol.collect() assert len(l) == 0 - -class TestDisabled: - def test_disabled_module(self, testdir): - modcol = testdir.getmodulecol(""" - disabled = True - def setup_module(mod): - raise ValueError - def test_method(): - pass - """) - l = modcol.collect() - assert len(l) == 1 - py.test.raises(Skipped, "modcol.setup()") - - def test_disabled_class(self, testdir): - modcol = testdir.getmodulecol(""" - class TestClass: - disabled = True - def test_method(self): - pass - """) - l = modcol.collect() - assert len(l) == 1 - modcol = l[0] - assert isinstance(modcol, py.test.collect.Class) - l = modcol.collect() - assert len(l) == 1 - py.test.raises(Skipped, "modcol.setup()") - - def test_disabled_class_functional(self, testdir): - reprec = testdir.inline_runsource(""" - class TestSimpleClassSetup: - disabled = True - def test_classlevel(self): pass - def test_classlevel2(self): pass - """) - reprec.assertoutcome(skipped=2) if py.std.sys.version_info > (3, 0): _func_name_attr = "__name__"