From 22c1ad9f7b097e3016a26a36083c44de2addc0cb Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 9 Sep 2009 23:07:42 +0200 Subject: [PATCH] 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 --- doc/changelog.txt | 3 +++ py/test/funcargs.py | 11 ++++++----- testing/execnet/conftest.py | 2 +- testing/pytest/test_funcargs.py | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index a9fd6743a..852e555e6 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,6 +1,9 @@ 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, add helpers to ease keeping 2 and 3k compatible code diff --git a/py/test/funcargs.py b/py/test/funcargs.py index e9b7dc0f6..a4684b551 100644 --- a/py/test/funcargs.py +++ b/py/test/funcargs.py @@ -126,7 +126,10 @@ class FuncargRequest: val = setup() cache[cachekey] = val 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 def getfuncargvalue(self, argname): @@ -157,7 +160,8 @@ class FuncargRequest: def _addfinalizer(self, finalizer, 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): """ 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 += "\n available funcargs: %s" %(", ".join(available),) raise self.Error(msg) - - - diff --git a/testing/execnet/conftest.py b/testing/execnet/conftest.py index 056d5397b..94c89503e 100644 --- a/testing/execnet/conftest.py +++ b/testing/execnet/conftest.py @@ -10,7 +10,7 @@ def pytest_generate_tests(metafunc): metafunc.addcall(id=gwtype, param=gwtype) def pytest_funcarg__gw(request): - scope = "session" # XXX module causes problems with -n 3! + scope = "session" if request.param == "popen": return request.cached_setup( setup=py.execnet.PopenGateway, diff --git a/testing/pytest/test_funcargs.py b/testing/pytest/test_funcargs.py index ca5ba29a6..23ee5a13a 100644 --- a/testing/pytest/test_funcargs.py +++ b/testing/pytest/test_funcargs.py @@ -240,6 +240,24 @@ class TestRequestCachedSetup: assert ret1 == ret1b 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): testdir.makepyfile(test_0=""" l = []