diff --git a/_pytest/__init__.py b/_pytest/__init__.py index e40bc8336..2e276a41a 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev16' +__version__ = '2.3.0.dev17' diff --git a/_pytest/python.py b/_pytest/python.py index 7ad1a085c..bd453933b 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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 = () diff --git a/setup.py b/setup.py index 6f050e569..6b1ce51e2 100644 --- a/setup.py +++ b/setup.py @@ -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'], diff --git a/testing/test_python.py b/testing/test_python.py index d0b1ebdaa..3f4a2e2be 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -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("""