also improve missing funcarg error for setup functions

This commit is contained in:
holger krekel 2012-08-08 14:53:47 +02:00
parent dd268c1b2b
commit 935761f098
2 changed files with 58 additions and 34 deletions

View File

@ -949,9 +949,9 @@ class FuncargRequest:
self.parentid)
return facdeflist
#def raiseerror(self, msg):
# """ raise a FuncargLookupError with the given message. """
# raise self.funcargmanager.FuncargLookupError(self.function, msg)
def raiseerror(self, msg):
""" raise a FuncargLookupError with the given message. """
raise self.funcargmanager.FuncargLookupError(self.function, msg)
@property
def function(self):
@ -1375,22 +1375,26 @@ class FuncargManager:
for setupcall in setuplist:
if setupcall.active:
continue
testcontext = TestContextSetup(request, setupcall)
kwargs = {}
for name in setupcall.funcargnames:
try:
kwargs[name] = request.getfuncargvalue(name)
except FuncargLookupError:
if name == "testcontext":
kwargs[name] = testcontext
else:
raise
scope = setupcall.scope or "function"
scol = setupcall.scopeitem = request._getscopeitem(scope)
self.session._setupstate.addfinalizer(setupcall.finish, scol)
for argname in setupcall.funcargnames: # XXX all deps?
self.addargfinalizer(setupcall.finish, argname)
setupcall.execute(kwargs)
request._factorystack.append(setupcall)
try:
testcontext = TestContextSetup(request, setupcall)
kwargs = {}
for name in setupcall.funcargnames:
try:
kwargs[name] = request.getfuncargvalue(name)
except FuncargLookupError:
if name == "testcontext":
kwargs[name] = testcontext
else:
raise
scope = setupcall.scope or "function"
scol = setupcall.scopeitem = request._getscopeitem(scope)
self.session._setupstate.addfinalizer(setupcall.finish, scol)
for argname in setupcall.funcargnames: # XXX all deps?
self.addargfinalizer(setupcall.finish, argname)
setupcall.execute(kwargs)
finally:
request._factorystack.remove(setupcall)
def addargfinalizer(self, finalizer, argname):
l = self._arg2finish.setdefault(argname, [])

View File

@ -2338,21 +2338,41 @@ class TestTestContextScopeAccess:
reprec.assertoutcome(passed=1)
def test_illdefined_factory(testdir):
testdir.makepyfile("""
import pytest
@pytest.factory()
def gen(request):
return 1
def test_something(gen):
pass
""")
result = testdir.runpytest()
assert result.ret != 0
result.stdout.fnmatch_lines([
"*def gen(request):*",
"*no factory*request*",
])
class TestErrors:
def test_subfactory_missing_funcarg(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.factory()
def gen(request):
return 1
def test_something(gen):
pass
""")
result = testdir.runpytest()
assert result.ret != 0
result.stdout.fnmatch_lines([
"*def gen(request):*",
"*no factory*request*",
"*1 error*",
])
def test_setupfunc_missing_funcarg(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.setup()
def gen(request):
return 1
def test_something():
pass
""")
result = testdir.runpytest()
assert result.ret != 0
result.stdout.fnmatch_lines([
"*def gen(request):*",
"*no factory*request*",
"*1 error*",
])
class TestTestContextVarious:
def test_newstyle_no_request(self, testdir):