ensure proper calling of finalizers in case of parametrization on classes

This commit is contained in:
holger krekel 2012-09-26 12:24:04 +02:00
parent 35cbb5791d
commit dbe66f468a
4 changed files with 31 additions and 2 deletions

View File

@ -1,2 +1,2 @@
#
__version__ = '2.3.0.dev16'
__version__ = '2.3.0.dev17'

View File

@ -1475,6 +1475,9 @@ class FuncargManager:
self.session._setupstate.addfinalizer(setupcall.finish, scol)
for argname in setupcall.funcargnames: # XXX all deps?
self.addargfinalizer(setupcall.finish, argname)
req = kwargs.get("request", None)
if req is not None:
mp.setattr(req, "addfinalizer", setupcall.addfinalizer)
# for unittest-setup methods we need to provide
# the correct instance
posargs = ()

View File

@ -24,7 +24,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.3.0.dev16',
version='2.3.0.dev17',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -2076,6 +2076,32 @@ class TestSetupManagement:
reprec.assertoutcome(passed=1)
def test_parametrization_setup_teardown_ordering(self, testdir):
testdir.makepyfile("""
import pytest
l = []
def pytest_generate_tests(metafunc):
if metafunc.cls is not None:
metafunc.parametrize("item", [1,2], scope="class")
class TestClass:
@pytest.setup(scope="class")
def addteardown(self, item, request):
request.addfinalizer(lambda: l.append("teardown-%d" % item))
l.append("setup-%d" % item)
def test_step1(self, item):
l.append("step1-%d" % item)
def test_step2(self, item):
l.append("step2-%d" % item)
def test_finish():
print l
assert l == ["setup-1", "step1-1", "step2-1", "teardown-1",
"setup-2", "step1-2", "step2-2", "teardown-2",]
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=5)
class TestFuncargMarker:
def test_parametrize(self, testdir):
testdir.makepyfile("""