re-introduce compatibility attributes on collection nodes to keep compatible with code like::

def pytest_collect_file(path, parent):
        ... parent.Module(...)

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-10-25 23:09:21 +02:00
parent 4480401119
commit 5fc87acf9b
4 changed files with 33 additions and 2 deletions

View File

@ -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']

View File

@ -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__,

View File

@ -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'],

View File

@ -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