generalize hook calling from collection nodes but stop short

of allowing general hooks in python test modules. It'd be
easily possible (a 1-line change) but considering it i refrained
from it because the collector API is a bit too low level.

pytest_generate_tests and funcarg factories have a limited
directly useful interface and are thus less confusing - those
are taking advantage of hook discovery in python test modules.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2009-12-30 10:42:01 +01:00
parent 631dfe9f13
commit ae63605ac0
7 changed files with 65 additions and 8 deletions
+4 -1
View File
@@ -19,7 +19,7 @@ class HookProxy:
raise AttributeError(name)
hookmethod = getattr(self.node.config.hook, name)
def call_matching_hooks(**kwargs):
plugins = self.node.config.getmatchingplugins(self.node.fspath)
plugins = self.node._getplugins()
return hookmethod.pcall(plugins, **kwargs)
return call_matching_hooks
@@ -43,6 +43,9 @@ class Node(object):
self.fspath = getattr(parent, 'fspath', None)
self.ihook = HookProxy(self)
def _getplugins(self):
return self.config._getmatchingplugins(self.fspath)
def _checkcollectable(self):
if not hasattr(self, 'fspath'):
self.parent._memocollect() # to reraise exception
+1 -1
View File
@@ -45,7 +45,7 @@ class Config(object):
self.trace("loaded conftestmodule %r" %(conftestmodule,))
self.pluginmanager.consider_conftest(conftestmodule)
def getmatchingplugins(self, fspath):
def _getmatchingplugins(self, fspath):
conftests = self._conftest._conftestpath2mod.values()
plugins = [x for x in self.pluginmanager.getplugins()
if x not in conftests]
+1 -4
View File
@@ -93,10 +93,7 @@ class FuncargRequest:
self.fspath = pyfuncitem.fspath
if hasattr(pyfuncitem, '_requestparam'):
self.param = pyfuncitem._requestparam
self._plugins = self.config.getmatchingplugins(self.fspath)
self._plugins.append(self.module)
if self.instance is not None:
self._plugins.append(self.instance)
self._plugins = pyfuncitem._getplugins(withpy=True)
self._funcargs = self._pyfuncitem.funcargs.copy()
self._name2factory = {}
self._currentarg = None
+11 -2
View File
@@ -34,6 +34,15 @@ class PyobjMixin(object):
return property(fget, fset, None, "underlying python object")
obj = obj()
def _getplugins(self, withpy=False):
plugins = self.config._getmatchingplugins(self.fspath)
if withpy:
plugins.append(self.getparent(py.test.collect.Module).obj)
inst = self.getparent(py.test.collect.Instance)
if inst is not None:
plugins.append(inst.obj)
return plugins
def _getobj(self):
return getattr(self.parent.obj, self.name)
@@ -138,8 +147,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
metafunc = funcargs.Metafunc(funcobj, config=self.config,
cls=cls, module=module)
gentesthook = self.config.hook.pytest_generate_tests
plugins = self.config.getmatchingplugins(self.fspath) + [module]
gentesthook.pcall(plugins, metafunc=metafunc)
gentesthook.pcall(self._getplugins(withpy=True), metafunc=metafunc)
if not metafunc._calls:
return self.Function(name, parent=self)
return funcargs.FunctionCollector(name=name,
@@ -327,6 +335,7 @@ class Function(FunctionMixin, py.test.collect.Item):
self.funcargs = {}
if callobj is not _dummy:
self._obj = callobj
self.function = getattr(self.obj, 'im_func', self.obj)
def _isyieldedfunction(self):
return self._args is not None