[svn r62430] honour unitttest function default values for pyfuncarg protocol
--HG-- branch : trunk
This commit is contained in:
parent
7765dda208
commit
fbe8315f76
|
@ -360,8 +360,18 @@ class Function(FunctionMixin, py.test.collect.Item):
|
|||
# standard Python Test function/method case
|
||||
funcobj = self.obj
|
||||
startindex = getattr(funcobj, 'im_self', None) and 1 or 0
|
||||
for argname in py.std.inspect.getargs(self.obj.func_code)[0][startindex:]:
|
||||
argnames = py.std.inspect.getargs(self.obj.func_code)[0]
|
||||
for i, argname in py.builtin.enumerate(argnames):
|
||||
if i < startindex:
|
||||
continue
|
||||
try:
|
||||
kwargs[argname] = self.lookup_onearg(argname)
|
||||
except LookupError, e:
|
||||
numdefaults = len(funcobj.func_defaults or ())
|
||||
if i + numdefaults >= len(argnames):
|
||||
continue # continue # seems that our args have defaults
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
pass # XXX lookup of arguments for yielded/generated tests as well
|
||||
return kwargs
|
||||
|
|
|
@ -229,9 +229,30 @@ class TestFunction:
|
|||
assert not f1 != f1_b
|
||||
|
||||
def test_pyfuncarg_lookupfails(self, testdir):
|
||||
item = testdir.getitem("def test_func(some, other): pass")
|
||||
item = testdir.getitem("def test_func(some): pass")
|
||||
kw = py.test.raises(LookupError, "item.lookup_allargs()")
|
||||
|
||||
def test_pyfuncarg_lookup_default(self, testdir):
|
||||
item = testdir.getitem("def test_func(some, other=42): pass")
|
||||
class Provider:
|
||||
def pytest_pyfuncarg_some(self, pyfuncitem):
|
||||
return pyfuncitem.name
|
||||
item._config.pytestplugins.register(Provider())
|
||||
kw = item.lookup_allargs()
|
||||
assert len(kw) == 1
|
||||
|
||||
def test_pyfuncarg_lookup_default_gets_overriden(self, testdir):
|
||||
item = testdir.getitem("def test_func(some=42, other=13): pass")
|
||||
class Provider:
|
||||
def pytest_pyfuncarg_other(self, pyfuncitem):
|
||||
return pyfuncitem.name
|
||||
item._config.pytestplugins.register(Provider())
|
||||
kw = item.lookup_allargs()
|
||||
assert len(kw) == 1
|
||||
name, value = kw.popitem()
|
||||
assert name == "other"
|
||||
assert value == item.name
|
||||
|
||||
def test_pyfuncarg_basic(self, testdir):
|
||||
item = testdir.getitem("def test_func(some, other): pass")
|
||||
class Provider:
|
||||
|
|
Loading…
Reference in New Issue