fix reporting failure

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-04-14 19:24:45 +02:00
parent 9c6a790992
commit 792dce025c
2 changed files with 25 additions and 20 deletions

View File

@ -373,7 +373,7 @@ class Function(FunctionMixin, py.test.collect.Item):
if i + numdefaults >= len(argnames): if i + numdefaults >= len(argnames):
continue # our args have defaults XXX issue warning? continue # our args have defaults XXX issue warning?
else: else:
raise # request.raiselookupfailed() request._raiselookupfailed()
def __eq__(self, other): def __eq__(self, other):
try: try:
@ -392,6 +392,8 @@ class Function(FunctionMixin, py.test.collect.Item):
class FuncargRequest: class FuncargRequest:
_argprefix = "pytest_funcarg__"
class Error(LookupError): class Error(LookupError):
""" error on performing funcarg request. """ """ error on performing funcarg request. """
@ -402,20 +404,25 @@ class FuncargRequest:
self.function = pyfuncitem.obj self.function = pyfuncitem.obj
self.funcname = pyfuncitem.name self.funcname = pyfuncitem.name
self.config = pyfuncitem.config self.config = pyfuncitem.config
extra = [] self._plugins = self._getplugins()
current = pyfuncitem self._methods = self.config.pluginmanager.listattr(
while not isinstance(current, Module): plugins=self._plugins,
current = current.parent attrname=self._argprefix + str(argname)
if isinstance(current, (Instance, Module)):
extra.insert(0, current.obj)
self._methods = self.pyfuncitem.config.pluginmanager.listattr(
"pytest_funcarg__" + str(argname),
extra=extra,
) )
def __repr__(self): def __repr__(self):
return "<FuncargRequest %r for %r>" %(self.argname, self.pyfuncitem) return "<FuncargRequest %r for %r>" %(self.argname, self.pyfuncitem)
def _getplugins(self):
plugins = []
current = self.pyfuncitem
while not isinstance(current, Module):
current = current.parent
if isinstance(current, (Instance, Module)):
plugins.insert(0, current.obj)
return self.config.pluginmanager.getplugins() + plugins
def call_next_provider(self): def call_next_provider(self):
if not self._methods: if not self._methods:
raise self.Error("no provider methods left") raise self.Error("no provider methods left")
@ -428,18 +435,16 @@ class FuncargRequest:
def getfspath(self): def getfspath(self):
return self.pyfuncitem.fspath return self.pyfuncitem.fspath
def _raisefuncargerror(self): def _raiselookupfailed(self):
metainfo = self.repr_metainfo()
available = [] available = []
plugins = list(self.config.pluginmanager.comregistry) for plugin in self._plugins:
#plugins.extend(self.config.pluginmanager.registry.plugins)
for plugin in plugins:
for name in vars(plugin.__class__): for name in vars(plugin.__class__):
if name.startswith(prefix): if name.startswith(self._argprefix):
name = name[len(prefix):] name = name[len(self._argprefix):]
if name not in available: if name not in available:
available.append(name) available.append(name)
msg = "funcargument %r not found for: %s" %(argname,metainfo.verboseline()) metainfo = self.pyfuncitem.repr_metainfo()
msg = "funcargument %r not found for: %s" %(self.argname,metainfo.verboseline())
msg += "\n available funcargs: %s" %(", ".join(available),) msg += "\n available funcargs: %s" %(", ".join(available),)
raise LookupError(msg) raise LookupError(msg)

View File

@ -4,13 +4,13 @@ class TestFuncargs:
def test_funcarg_lookupfails(self, testdir): def test_funcarg_lookupfails(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
class ConftestPlugin: class ConftestPlugin:
def pytest_funcarg__xyz(self, request): def pytest_funcarg__xyzsomething(self, request):
return 42 return 42
""") """)
item = testdir.getitem("def test_func(some): pass") item = testdir.getitem("def test_func(some): pass")
exc = py.test.raises(LookupError, "item.setupargs()") exc = py.test.raises(LookupError, "item.setupargs()")
s = str(exc.value) s = str(exc.value)
assert s.find("something") != -1 assert s.find("xyzsomething") != -1
def test_funcarg_lookup_default(self, testdir): def test_funcarg_lookup_default(self, testdir):
item = testdir.getitem("def test_func(some, other=42): pass") item = testdir.getitem("def test_func(some, other=42): pass")