From 5fc87acf9b3e2f7edbc2f387e98d9fe4a9429a49 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 25 Oct 2010 23:09:21 +0200 Subject: [PATCH] re-introduce compatibility attributes on collection nodes to keep compatible with code like:: def pytest_collect_file(path, parent): ... parent.Module(...) --HG-- branch : trunk --- pytest/__init__.py | 2 +- pytest/plugin/session.py | 14 ++++++++++++++ setup.py | 2 +- testing/test_collect.py | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pytest/__init__.py b/pytest/__init__.py index b6e4db4df..280549c0e 100644 --- a/pytest/__init__.py +++ b/pytest/__init__.py @@ -5,7 +5,7 @@ see http://pytest.org for documentation and details (c) Holger Krekel and others, 2004-2010 """ -__version__ = '2.0.0.dev8' +__version__ = '2.0.0.dev9' __all__ = ['config', 'cmdline'] diff --git a/pytest/plugin/session.py b/pytest/plugin/session.py index 388220215..c4699f788 100644 --- a/pytest/plugin/session.py +++ b/pytest/plugin/session.py @@ -308,6 +308,14 @@ class HookProxy: return hookmethod.pcall(plugins, **kwargs) return call_matching_hooks +def compatproperty(name): + def fget(self): + #print "retrieving %r property from %s" %(name, self.fspath) + py.log._apiwarn("2.0", "use py.test.collect.%s for " + "Collection classes" % name) + return getattr(pytest.collect, name) + return property(fget) + class Node(object): """ base class for all Nodes in the collection tree. Collector subclasses have children, Items are terminal nodes.""" @@ -330,6 +338,12 @@ class Node(object): self.ihook = HookProxy(self) self.keywords = {self.name: True} + Module = compatproperty("Module") + Class = compatproperty("Class") + Function = compatproperty("Function") + File = compatproperty("File") + Item = compatproperty("Item") + def __repr__(self): if getattr(self.config.option, 'debug', False): return "<%s %r %0x>" %(self.__class__.__name__, diff --git a/setup.py b/setup.py index f24fa28c1..c53444bcf 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.0.dev8', + version='2.0.0.dev9', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_collect.py b/testing/test_collect.py index 33b903036..c045b49c1 100644 --- a/testing/test_collect.py +++ b/testing/test_collect.py @@ -6,6 +6,23 @@ class TestCollector: assert not issubclass(Collector, Item) assert not issubclass(Item, Collector) + def test_compat_attributes(self, testdir, recwarn): + modcol = testdir.getmodulecol(""" + def test_pass(): pass + def test_fail(): assert 0 + """) + recwarn.clear() + assert modcol.Module == py.test.collect.Module + recwarn.pop(DeprecationWarning) + assert modcol.Class == py.test.collect.Class + recwarn.pop(DeprecationWarning) + assert modcol.Item == py.test.collect.Item + recwarn.pop(DeprecationWarning) + assert modcol.File == py.test.collect.File + recwarn.pop(DeprecationWarning) + assert modcol.Function == py.test.collect.Function + recwarn.pop(DeprecationWarning) + def test_check_equality(self, testdir): modcol = testdir.getmodulecol(""" def test_pass(): pass