[py-svn] commit/pytest: hpk42: ensure proper calling of finalizers in case of parametrization on classes

Bitbucket commits-noreply at bitbucket.org
Wed Sep 26 12:46:33 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/1c8e15ae7969/
changeset:   1c8e15ae7969
user:        hpk42
date:        2012-09-26 12:24:04
summary:     ensure proper calling of finalizers in case of parametrization on classes
affected #:  4 files

diff -r 76972802c0339c9309af31158983d683e01461a4 -r 1c8e15ae79692b3c49204fca94769e0ee7e03429 _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.3.0.dev16'
+__version__ = '2.3.0.dev17'


diff -r 76972802c0339c9309af31158983d683e01461a4 -r 1c8e15ae79692b3c49204fca94769e0ee7e03429 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1475,6 +1475,9 @@
                 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 -r 76972802c0339c9309af31158983d683e01461a4 -r 1c8e15ae79692b3c49204fca94769e0ee7e03429 setup.py
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@
         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 -r 76972802c0339c9309af31158983d683e01461a4 -r 1c8e15ae79692b3c49204fca94769e0ee7e03429 testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -2076,6 +2076,32 @@
         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("""

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list