allow registration of "funcarg" marked factories
This commit is contained in:
parent
80db25822c
commit
396045e53f
|
@ -463,11 +463,20 @@ class FuncargManager:
|
||||||
self._holderobjseen.add(holderobj)
|
self._holderobjseen.add(holderobj)
|
||||||
for name in dir(holderobj):
|
for name in dir(holderobj):
|
||||||
#print "check", holderobj, name
|
#print "check", holderobj, name
|
||||||
if name.startswith(self._argprefix):
|
obj = getattr(holderobj, name)
|
||||||
fname = name[len(self._argprefix):]
|
# funcarg factories either have a pytest_funcarg__ prefix
|
||||||
faclist = self.arg2facspec.setdefault(fname, [])
|
# or are "funcarg" marked
|
||||||
obj = getattr(holderobj, name)
|
if hasattr(obj, "funcarg"):
|
||||||
faclist.append((nodeid, obj))
|
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):
|
def getfactorylist(self, argname, nodeid, function, raising=True):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1805,3 +1805,25 @@ class TestFuncargMarker:
|
||||||
"*ScopeMismatch*You tried*function*from*session*",
|
"*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