[svn r63337] provide more info for the pyfuncarg failing lookup
improve docstring --HG-- branch : trunk
This commit is contained in:
parent
1930f50bc2
commit
ee902a2d06
|
@ -1,6 +1,6 @@
|
|||
"""
|
||||
for marking and reporting "expected to fail" tests.
|
||||
@py.test.mark(xfail="needs refactoring")
|
||||
@py.test.mark.xfail("needs refactoring")
|
||||
def test_hello():
|
||||
...
|
||||
assert 0
|
||||
|
|
|
@ -375,11 +375,12 @@ class Function(FunctionMixin, py.test.collect.Item):
|
|||
return kwargs
|
||||
|
||||
def lookup_onearg(self, argname):
|
||||
prefix = "pytest_pyfuncarg_"
|
||||
try:
|
||||
makerlist = self.config._getmakerlist(argname)
|
||||
except KeyError:
|
||||
makerlist = []
|
||||
l = self.config.pytestplugins.listattr("pytest_pyfuncarg_" + argname)
|
||||
l = self.config.pytestplugins.listattr(prefix + argname)
|
||||
makerlist.extend(l)
|
||||
mc = py._com.MultiCall(makerlist, self)
|
||||
#print "mc.methods", mc.methods
|
||||
|
@ -387,11 +388,22 @@ class Function(FunctionMixin, py.test.collect.Item):
|
|||
if value is not None:
|
||||
return value
|
||||
else:
|
||||
metainfo = self.repr_metainfo()
|
||||
#self.config.bus.notify("pyfuncarg_lookuperror", argname)
|
||||
msg = "funcargument %r not found for: %s" %(argname,metainfo.verboseline())
|
||||
msg += "\n list of makers: %r" %(l,)
|
||||
raise LookupError(msg)
|
||||
self._raisefuncargerror(argname, prefix)
|
||||
|
||||
def _raisefuncargerror(self, argname, prefix="pytest_pyfuncarg_"):
|
||||
metainfo = self.repr_metainfo()
|
||||
available = []
|
||||
plugins = self.config.pytestplugins._plugins.values()
|
||||
plugins.extend(self.config.pytestplugins.pyplugins._plugins)
|
||||
for plugin in plugins:
|
||||
for name in vars(plugin.__class__):
|
||||
if name.startswith(prefix):
|
||||
name = name[len(prefix):]
|
||||
if name not in available:
|
||||
available.append(name)
|
||||
msg = "funcargument %r not found for: %s" %(argname,metainfo.verboseline())
|
||||
msg += "\n available funcargs: %s" %(", ".join(available),)
|
||||
raise LookupError(msg)
|
||||
|
||||
def __eq__(self, other):
|
||||
try:
|
||||
|
|
|
@ -250,8 +250,15 @@ class TestFunction:
|
|||
assert not f1 != f1_b
|
||||
|
||||
def test_pyfuncarg_lookupfails(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
class ConftestPlugin:
|
||||
def pytest_pyfuncarg_something(self, pyfuncitem):
|
||||
return 42
|
||||
""")
|
||||
item = testdir.getitem("def test_func(some): pass")
|
||||
kw = py.test.raises(LookupError, "item.lookup_allargs()")
|
||||
exc = py.test.raises(LookupError, "item.lookup_allargs()")
|
||||
s = str(exc.value)
|
||||
assert s.find("something") != -1
|
||||
|
||||
def test_pyfuncarg_lookup_default(self, testdir):
|
||||
item = testdir.getitem("def test_func(some, other=42): pass")
|
||||
|
|
Loading…
Reference in New Issue