fix a bug with funcarg setup and remove XXX comment because "scope=module" now would work but leaving it as session for now.
--HG-- branch : trunk
This commit is contained in:
parent
6d84da39e4
commit
22c1ad9f7b
|
@ -1,6 +1,9 @@
|
||||||
Changes between 1.0.x and 'trunk'
|
Changes between 1.0.x and 'trunk'
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
|
* fix a funcarg cached_setup bug probably only occuring
|
||||||
|
in distributed testing and "module" scope with teardown.
|
||||||
|
|
||||||
* consolidate builtins implementation to be compatible with >=2.3,
|
* consolidate builtins implementation to be compatible with >=2.3,
|
||||||
add helpers to ease keeping 2 and 3k compatible code
|
add helpers to ease keeping 2 and 3k compatible code
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,10 @@ class FuncargRequest:
|
||||||
val = setup()
|
val = setup()
|
||||||
cache[cachekey] = val
|
cache[cachekey] = val
|
||||||
if teardown is not None:
|
if teardown is not None:
|
||||||
self._addfinalizer(lambda: teardown(val), scope=scope)
|
def finalizer():
|
||||||
|
del cache[cachekey]
|
||||||
|
teardown(val)
|
||||||
|
self._addfinalizer(finalizer, scope=scope)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def getfuncargvalue(self, argname):
|
def getfuncargvalue(self, argname):
|
||||||
|
@ -157,7 +160,8 @@ class FuncargRequest:
|
||||||
|
|
||||||
def _addfinalizer(self, finalizer, scope):
|
def _addfinalizer(self, finalizer, scope):
|
||||||
colitem = self._getscopeitem(scope)
|
colitem = self._getscopeitem(scope)
|
||||||
self.config._setupstate.addfinalizer(finalizer=finalizer, colitem=colitem)
|
self.config._setupstate.addfinalizer(
|
||||||
|
finalizer=finalizer, colitem=colitem)
|
||||||
|
|
||||||
def addfinalizer(self, finalizer):
|
def addfinalizer(self, finalizer):
|
||||||
""" call the given finalizer after test function finished execution. """
|
""" call the given finalizer after test function finished execution. """
|
||||||
|
@ -179,6 +183,3 @@ class FuncargRequest:
|
||||||
msg = "funcargument %r not found for: %s" %(argname, line)
|
msg = "funcargument %r not found for: %s" %(argname, line)
|
||||||
msg += "\n available funcargs: %s" %(", ".join(available),)
|
msg += "\n available funcargs: %s" %(", ".join(available),)
|
||||||
raise self.Error(msg)
|
raise self.Error(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ def pytest_generate_tests(metafunc):
|
||||||
metafunc.addcall(id=gwtype, param=gwtype)
|
metafunc.addcall(id=gwtype, param=gwtype)
|
||||||
|
|
||||||
def pytest_funcarg__gw(request):
|
def pytest_funcarg__gw(request):
|
||||||
scope = "session" # XXX module causes problems with -n 3!
|
scope = "session"
|
||||||
if request.param == "popen":
|
if request.param == "popen":
|
||||||
return request.cached_setup(
|
return request.cached_setup(
|
||||||
setup=py.execnet.PopenGateway,
|
setup=py.execnet.PopenGateway,
|
||||||
|
|
|
@ -240,6 +240,24 @@ class TestRequestCachedSetup:
|
||||||
assert ret1 == ret1b
|
assert ret1 == ret1b
|
||||||
assert ret2 == ret2b
|
assert ret2 == ret2b
|
||||||
|
|
||||||
|
def test_request_cachedsetup_cache_deletion(self, testdir):
|
||||||
|
item1 = testdir.getitem("def test_func(): pass")
|
||||||
|
req1 = funcargs.FuncargRequest(item1)
|
||||||
|
l = []
|
||||||
|
def setup():
|
||||||
|
l.append("setup")
|
||||||
|
def teardown(val):
|
||||||
|
l.append("teardown")
|
||||||
|
ret1 = req1.cached_setup(setup, teardown, scope="function")
|
||||||
|
assert l == ['setup']
|
||||||
|
# artificial call of finalizer
|
||||||
|
req1.config._setupstate._callfinalizers(item1)
|
||||||
|
assert l == ["setup", "teardown"]
|
||||||
|
ret2 = req1.cached_setup(setup, teardown, scope="function")
|
||||||
|
assert l == ["setup", "teardown", "setup"]
|
||||||
|
req1.config._setupstate._callfinalizers(item1)
|
||||||
|
assert l == ["setup", "teardown", "setup", "teardown"]
|
||||||
|
|
||||||
def test_request_cached_setup_functional(self, testdir):
|
def test_request_cached_setup_functional(self, testdir):
|
||||||
testdir.makepyfile(test_0="""
|
testdir.makepyfile(test_0="""
|
||||||
l = []
|
l = []
|
||||||
|
|
Loading…
Reference in New Issue