ensure proper calling of finalizers in case of parametrization on classes
This commit is contained in:
parent
35cbb5791d
commit
dbe66f468a
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.3.0.dev16'
|
__version__ = '2.3.0.dev17'
|
||||||
|
|
|
@ -1475,6 +1475,9 @@ class FuncargManager:
|
||||||
self.session._setupstate.addfinalizer(setupcall.finish, scol)
|
self.session._setupstate.addfinalizer(setupcall.finish, scol)
|
||||||
for argname in setupcall.funcargnames: # XXX all deps?
|
for argname in setupcall.funcargnames: # XXX all deps?
|
||||||
self.addargfinalizer(setupcall.finish, argname)
|
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
|
# for unittest-setup methods we need to provide
|
||||||
# the correct instance
|
# the correct instance
|
||||||
posargs = ()
|
posargs = ()
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.3.0.dev16',
|
version='2.3.0.dev17',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
|
@ -2076,6 +2076,32 @@ class TestSetupManagement:
|
||||||
reprec.assertoutcome(passed=1)
|
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:
|
class TestFuncargMarker:
|
||||||
def test_parametrize(self, testdir):
|
def test_parametrize(self, testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue