diff --git a/_pytest/python.py b/_pytest/python.py index f6474581a..a0a8ca8e2 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -208,7 +208,10 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector): metafunc = Metafunc(funcobj, config=self.config, cls=cls, module=module) gentesthook = self.config.hook.pytest_generate_tests - plugins = getplugins(self, withpy=True) + extra = [module] + if cls is not None: + extra.append(cls()) + plugins = self.getplugins() + extra gentesthook.pcall(plugins, metafunc=metafunc) if not metafunc._calls: return Function(name, parent=self) @@ -497,17 +500,6 @@ def fillfuncargs(function): request = FuncargRequest(pyfuncitem=function) request._fillfuncargs() -def getplugins(node, withpy=False): # might by any node - plugins = node.config._getmatchingplugins(node.fspath) - if withpy: - mod = node.getparent(pytest.Module) - if mod is not None: - plugins.append(mod.obj) - inst = node.getparent(pytest.Instance) - if inst is not None: - plugins.append(inst.obj) - return plugins - _notexists = object() class CallSpec: def __init__(self, funcargs, id, param): @@ -572,7 +564,8 @@ class FuncargRequest: self._pyfuncitem = pyfuncitem if hasattr(pyfuncitem, '_requestparam'): self.param = pyfuncitem._requestparam - self._plugins = getplugins(pyfuncitem, withpy=True) + extra = filter(None, [self.module, self.instance]) + self._plugins = pyfuncitem.getplugins() + extra self._funcargs = self._pyfuncitem.funcargs.copy() self._name2factory = {} self._currentarg = None @@ -741,9 +734,9 @@ def showfuncargs(config): session = Session(config) session.perform_collect() if session.items: - plugins = getplugins(session.items[0]) + plugins = session.items[0].getplugins() else: - plugins = getplugins(session) + plugins = session.getplugins() curdir = py.path.local() tw = py.io.TerminalWriter() verbose = config.getvalue("verbose") diff --git a/_pytest/session.py b/_pytest/session.py index 1fdfd72b2..534a199f2 100644 --- a/_pytest/session.py +++ b/_pytest/session.py @@ -221,6 +221,9 @@ class Node(object): def listnames(self): return [x.name for x in self.listchain()] + def getplugins(self): + return self.config._getmatchingplugins(self.fspath) + def getparent(self, cls): current = self while current and not isinstance(current, cls):