[py-svn] commit/pytest: RonnyPfannschmidt: strip bound wrappers of class setup/tardown, fixes #140

Bitbucket commits-noreply at bitbucket.org
Sun May 6 23:04:43 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/e39c5ab74536/
changeset:   e39c5ab74536
user:        RonnyPfannschmidt
date:        2012-05-06 23:03:16
summary:     strip bound wrappers of class setup/tardown, fixes #140

on python3 im_func is replaced by __func__
affected #:  2 files

diff -r 1ab662c89077009ac5f7a66622e77e85b87c6e0c -r e39c5ab74536172b6698b32594779d39e0c162b9 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -311,12 +311,14 @@
         setup_class = getattr(self.obj, 'setup_class', None)
         if setup_class is not None:
             setup_class = getattr(setup_class, 'im_func', setup_class)
+            setup_class = getattr(setup_class, '__func__', setup_class)
             setup_class(self.obj)
 
     def teardown(self):
         teardown_class = getattr(self.obj, 'teardown_class', None)
         if teardown_class is not None:
             teardown_class = getattr(teardown_class, 'im_func', teardown_class)
+            teardown_class = getattr(teardown_class, '__func__', teardown_class)
             teardown_class(self.obj)
 
 class Instance(PyCollectorMixin, pytest.Collector):


diff -r 1ab662c89077009ac5f7a66622e77e85b87c6e0c -r e39c5ab74536172b6698b32594779d39e0c162b9 testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -56,6 +56,24 @@
             "*collected 0*",
         ])
 
+    def test_setup_teardown_class_as_classmethod(self, testdir):
+        testdir.makepyfile("""
+            class TestClassMethod:
+                @classmethod
+                def setup_class(cls):
+                    pass
+                def test_1(self):
+                    pass
+                @classmethod
+                def teardown_class(cls):
+                    pass
+        """)
+        result = testdir.runpytest()
+        result.stdout.fnmatch_lines([
+            "*1 passed*",
+        ])
+
+
 class TestGenerator:
     def test_generative_functions(self, testdir):
         modcol = testdir.getmodulecol("""

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