[py-svn] py-trunk commit ed40b4eda543: fix aimed at passing jstests functional tests: allow to have _fillfuncargs() called even for non-pycollect-object test-items.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 30 14:06:04 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1262178341 -3600
# Node ID ed40b4eda543c3e88efd7de7555fb0ebe36cd77d
# Parent 1a34c06b5a815ae8130432b6df09f765d6328fcd
fix aimed at passing jstests functional tests: allow to have _fillfuncargs() called even for non-pycollect-object test-items.
--- 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
--- 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.te
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,
--- 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
--- a/testing/pytest/test_funcargs.py
+++ b/testing/pytest/test_funcargs.py
@@ -519,3 +519,26 @@ def test_conftest_funcargs_only_availabl
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
+
More information about the pytest-commit
mailing list