avoid deprecation warnings for our internal accesses

This commit is contained in:
holger krekel 2011-03-05 14:16:27 +01:00
parent 22fac92ca0
commit 07cee24122
4 changed files with 17 additions and 12 deletions

View File

@ -32,6 +32,8 @@ Changes between 2.0.1 and 2.0.2
- fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular - fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular
thanks to Laura Creighton who also revieved parts of the documentation. thanks to Laura Creighton who also revieved parts of the documentation.
- more precise (avoiding of) deprecation warnings for node.Class|Function accesses
Changes between 2.0.0 and 2.0.1 Changes between 2.0.0 and 2.0.1
---------------------------------------------- ----------------------------------------------

View File

@ -121,9 +121,6 @@ class HookProxy:
def compatproperty(name): def compatproperty(name):
def fget(self): def fget(self):
#print "retrieving %r property from %s" %(name, self.fspath)
py.log._apiwarn("2.0", "use pytest.%s for "
"test collection and item classes" % name)
return getattr(pytest, name) return getattr(pytest, name)
return property(fget, None, None, return property(fget, None, None,
"deprecated attribute %r, use pytest.%s" % (name,name)) "deprecated attribute %r, use pytest.%s" % (name,name))
@ -157,6 +154,14 @@ class Node(object):
File = compatproperty("File") File = compatproperty("File")
Item = compatproperty("Item") Item = compatproperty("Item")
def _getcustomclass(self, name):
cls = getattr(self, name)
if cls != getattr(pytest, name):
py.log._apiwarn("2.0", "use of node.%s is deprecated, "
"use pytest_pycollect_makeitem(...) to create custom "
"collection nodes" % name)
return cls
def __repr__(self): def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, getattr(self, 'name', None)) return "<%s %r>" %(self.__class__.__name__, getattr(self, 'name', None))

View File

@ -73,7 +73,8 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
if collector._istestclasscandidate(name, obj): if collector._istestclasscandidate(name, obj):
#if hasattr(collector.obj, 'unittest'): #if hasattr(collector.obj, 'unittest'):
# return # we assume it's a mixin class for a TestCase derived one # return # we assume it's a mixin class for a TestCase derived one
return collector.Class(name, parent=collector) Class = collector._getcustomclass("Class")
return Class(name, parent=collector)
elif collector.funcnamefilter(name) and hasattr(obj, '__call__'): elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
if is_generator(obj): if is_generator(obj):
return Generator(name, parent=collector) return Generator(name, parent=collector)
@ -213,16 +214,18 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
extra.append(cls()) extra.append(cls())
plugins = self.getplugins() + extra plugins = self.getplugins() + extra
gentesthook.pcall(plugins, metafunc=metafunc) gentesthook.pcall(plugins, metafunc=metafunc)
Function = self._getcustomclass("Function")
if not metafunc._calls: if not metafunc._calls:
return self.Function(name, parent=self) return Function(name, parent=self)
l = [] l = []
for callspec in metafunc._calls: for callspec in metafunc._calls:
subname = "%s[%s]" %(name, callspec.id) subname = "%s[%s]" %(name, callspec.id)
function = self.Function(name=subname, parent=self, function = Function(name=subname, parent=self,
callspec=callspec, callobj=funcobj, keywords={callspec.id:True}) callspec=callspec, callobj=funcobj, keywords={callspec.id:True})
l.append(function) l.append(function)
return l return l
class Module(pytest.File, PyCollectorMixin): class Module(pytest.File, PyCollectorMixin):
def _getobj(self): def _getobj(self):
return self._memoizedcall('_obj', self._importtestmodule) return self._memoizedcall('_obj', self._importtestmodule)
@ -272,7 +275,7 @@ class Module(pytest.File, PyCollectorMixin):
class Class(PyCollectorMixin, pytest.Collector): class Class(PyCollectorMixin, pytest.Collector):
def collect(self): def collect(self):
return [self.Instance(name="()", parent=self)] return [self._getcustomclass("Instance")(name="()", parent=self)]
def setup(self): def setup(self):
setup_class = getattr(self.obj, 'setup_class', None) setup_class = getattr(self.obj, 'setup_class', None)

View File

@ -15,15 +15,10 @@ class TestCollector:
""") """)
recwarn.clear() recwarn.clear()
assert modcol.Module == pytest.Module assert modcol.Module == pytest.Module
recwarn.pop(DeprecationWarning)
assert modcol.Class == pytest.Class assert modcol.Class == pytest.Class
recwarn.pop(DeprecationWarning)
assert modcol.Item == pytest.Item assert modcol.Item == pytest.Item
recwarn.pop(DeprecationWarning)
assert modcol.File == pytest.File assert modcol.File == pytest.File
recwarn.pop(DeprecationWarning)
assert modcol.Function == pytest.Function assert modcol.Function == pytest.Function
recwarn.pop(DeprecationWarning)
def test_check_equality(self, testdir): def test_check_equality(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""