fix aimed at passing jstests functional tests: allow to have _fillfuncargs() called even for non-pycollect-object test-items.
--HG-- branch : trunk
This commit is contained in:
parent
89f178bf4d
commit
30bbf3b042
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue