allow registration of "funcarg" marked factories
This commit is contained in:
parent
80db25822c
commit
396045e53f
|
@ -463,10 +463,19 @@ class FuncargManager:
|
|||
self._holderobjseen.add(holderobj)
|
||||
for name in dir(holderobj):
|
||||
#print "check", holderobj, name
|
||||
if name.startswith(self._argprefix):
|
||||
fname = name[len(self._argprefix):]
|
||||
faclist = self.arg2facspec.setdefault(fname, [])
|
||||
obj = getattr(holderobj, name)
|
||||
# funcarg factories either have a pytest_funcarg__ prefix
|
||||
# or are "funcarg" marked
|
||||
if hasattr(obj, "funcarg"):
|
||||
if name.startswith(self._argprefix):
|
||||
argname = name[len(self._argprefix):]
|
||||
else:
|
||||
argname = name
|
||||
elif name.startswith(self._argprefix):
|
||||
argname = name[len(self._argprefix):]
|
||||
else:
|
||||
continue
|
||||
faclist = self.arg2facspec.setdefault(argname, [])
|
||||
faclist.append((nodeid, obj))
|
||||
|
||||
def getfactorylist(self, argname, nodeid, function, raising=True):
|
||||
|
|
|
@ -1805,3 +1805,25 @@ class TestFuncargMarker:
|
|||
"*ScopeMismatch*You tried*function*from*session*",
|
||||
])
|
||||
|
||||
def test_register_only_with_mark(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
finalized = []
|
||||
created = []
|
||||
@pytest.mark.funcarg
|
||||
def arg(request):
|
||||
return 1
|
||||
""")
|
||||
testdir.makepyfile(
|
||||
test_mod1="""
|
||||
import pytest
|
||||
@pytest.mark.funcarg
|
||||
def arg(request):
|
||||
return request.getfuncargvalue("arg") + 1
|
||||
def test_1(arg):
|
||||
assert arg == 2
|
||||
""")
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue