remove scope argument from request.addfinalizer
--HG-- branch : 1.0.x
This commit is contained in:
@@ -113,7 +113,7 @@ class FuncargRequest:
|
||||
val = setup()
|
||||
cache[cachekey] = val
|
||||
if teardown is not None:
|
||||
self.addfinalizer(lambda: teardown(val), scope=scope)
|
||||
self._addfinalizer(lambda: teardown(val), scope=scope)
|
||||
return val
|
||||
|
||||
def getfuncargvalue(self, argname):
|
||||
@@ -142,10 +142,14 @@ class FuncargRequest:
|
||||
return None
|
||||
raise ValueError("unknown finalization scope %r" %(scope,))
|
||||
|
||||
def addfinalizer(self, finalizer, scope="function"):
|
||||
def _addfinalizer(self, finalizer, scope):
|
||||
colitem = self._getscopeitem(scope)
|
||||
self.config._setupstate.addfinalizer(finalizer=finalizer, colitem=colitem)
|
||||
|
||||
def addfinalizer(self, finalizer):
|
||||
""" call the given finalizer after test function finished execution. """
|
||||
self._addfinalizer(finalizer, scope="function")
|
||||
|
||||
def __repr__(self):
|
||||
return "<FuncargRequest for %r>" %(self._pyfuncitem)
|
||||
|
||||
|
||||
@@ -163,15 +163,11 @@ class TestRequest:
|
||||
req._fillfuncargs()
|
||||
assert item.funcargs == {'something': 1}
|
||||
|
||||
def test_request_addfinalizer_scopes(self, testdir):
|
||||
def test_request_addfinalizer(self, testdir):
|
||||
item = testdir.getitem("""
|
||||
teardownlist = []
|
||||
def pytest_funcarg__something(request):
|
||||
for scope in ("function", "module", "session"):
|
||||
request.addfinalizer(
|
||||
lambda x=scope: teardownlist.append(x),
|
||||
scope=scope)
|
||||
|
||||
request.addfinalizer(lambda: teardownlist.append(1))
|
||||
def test_func(something): pass
|
||||
""")
|
||||
req = funcargs.FuncargRequest(item)
|
||||
@@ -183,16 +179,7 @@ class TestRequest:
|
||||
assert not teardownlist
|
||||
ss.teardown_exact(item)
|
||||
print ss.stack
|
||||
assert teardownlist == ['function']
|
||||
ss.teardown_exact(item.parent)
|
||||
assert teardownlist == ['function', 'module']
|
||||
ss.teardown_all()
|
||||
assert teardownlist == ['function', 'module', 'session']
|
||||
|
||||
def test_request_addfinalizer_unknown_scope(self, testdir):
|
||||
item = testdir.getitem("def test_func(): pass")
|
||||
req = funcargs.FuncargRequest(item)
|
||||
py.test.raises(ValueError, "req.addfinalizer(None, scope='xyz')")
|
||||
assert teardownlist == [1]
|
||||
|
||||
def test_request_getmodulepath(self, testdir):
|
||||
modcol = testdir.getmodulecol("def test_somefunc(): pass")
|
||||
@@ -200,7 +187,6 @@ class TestRequest:
|
||||
req = funcargs.FuncargRequest(item)
|
||||
assert req.fspath == modcol.fspath
|
||||
|
||||
|
||||
class TestRequestCachedSetup:
|
||||
def test_request_cachedsetup(self, testdir):
|
||||
item1,item2 = testdir.getitems("""
|
||||
|
||||
Reference in New Issue
Block a user