diff --git a/py/impl/test/collect.py b/py/impl/test/collect.py index 84a7b768a..e4a38e4be 100644 --- a/py/impl/test/collect.py +++ b/py/impl/test/collect.py @@ -19,7 +19,7 @@ class HookProxy: raise AttributeError(name) hookmethod = getattr(self.node.config.hook, name) def call_matching_hooks(**kwargs): - plugins = self.node._getplugins() + plugins = self.node.config._getmatchingplugins(self.node.fspath) return hookmethod.pcall(plugins, **kwargs) return call_matching_hooks @@ -43,9 +43,6 @@ 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 diff --git a/py/impl/test/funcargs.py b/py/impl/test/funcargs.py index 520615b82..29af77c48 100644 --- a/py/impl/test/funcargs.py +++ b/py/impl/test/funcargs.py @@ -15,6 +15,16 @@ 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(py.test.collect.Module) + if mod is not None: + plugins.append(mod.obj) + inst = node.getparent(py.test.collect.Instance) + if inst is not None: + plugins.append(inst.obj) + return plugins _notexists = object() class CallSpec: @@ -93,7 +103,7 @@ class FuncargRequest: self.fspath = pyfuncitem.fspath if hasattr(pyfuncitem, '_requestparam'): self.param = pyfuncitem._requestparam - self._plugins = pyfuncitem._getplugins(withpy=True) + self._plugins = getplugins(pyfuncitem, withpy=True) self._funcargs = self._pyfuncitem.funcargs.copy() self._name2factory = {} self._currentarg = None diff --git a/py/impl/test/pycollect.py b/py/impl/test/pycollect.py index 3802cfaa8..784831144 100644 --- a/py/impl/test/pycollect.py +++ b/py/impl/test/pycollect.py @@ -34,15 +34,6 @@ 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) @@ -147,7 +138,8 @@ 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 - gentesthook.pcall(self._getplugins(withpy=True), metafunc=metafunc) + plugins = funcargs.getplugins(self, withpy=True) + gentesthook.pcall(plugins, metafunc=metafunc) if not metafunc._calls: return self.Function(name, parent=self) return funcargs.FunctionCollector(name=name, diff --git a/testing/pytest/test_funcargs.py b/testing/pytest/test_funcargs.py index a2807166e..4ed1734e7 100644 --- a/testing/pytest/test_funcargs.py +++ b/testing/pytest/test_funcargs.py @@ -519,3 +519,26 @@ def test_conftest_funcargs_only_available_in_subdir(testdir): result.stdout.fnmatch_lines([ "*2 passed*" ]) + +def test_funcarg_non_pycollectobj(testdir): # rough jstests usage + testdir.makeconftest(""" + import py + def pytest_pycollect_makeitem(collector, name, obj): + if name == "MyClass": + return MyCollector(name, parent=collector) + class MyCollector(py.test.collect.Collector): + def reportinfo(self): + return self.fspath, 3, "xyz" + """) + modcol = testdir.getmodulecol(""" + def pytest_funcarg__arg1(request): + return 42 + class MyClass: + pass + """) + clscol = modcol.collect()[0] + clscol.obj = lambda arg1: None + clscol.funcargs = {} + funcargs.fillfuncargs(clscol) + assert clscol.funcargs['arg1'] == 42 +