[py-svn] pytest commit 079d3f4bb7b3: allow setup_class in unittest test cases

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 24 00:28:02 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1290554619 -3600
# Node ID 079d3f4bb7b3757e1d3a42cde8f2dad997523953
# Parent  3b14dfd0a106c184022acc1e8cda36c42ae9ec61
allow setup_class in unittest test cases

--- a/_pytest/unittest.py
+++ b/_pytest/unittest.py
@@ -26,11 +26,13 @@ class UnitTestCase(pytest.Class):
         meth = getattr(self.obj, 'setUpClass', None)
         if meth is not None:
             meth()
+        super(UnitTestCase, self).setup()
 
     def teardown(self):
         meth = getattr(self.obj, 'tearDownClass', None)
         if meth is not None:
             meth()
+        super(UnitTestCase, self).teardown()
 
 class TestCaseFunction(pytest.Function):
     _excinfo = None

--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def main():
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.0.0.dev35',
+        version='2.0.0.dev36',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

--- a/testing/test_unittest.py
+++ b/testing/test_unittest.py
@@ -82,7 +82,7 @@ def test_module_level_pytestmark(testdir
     reprec = testdir.inline_run(testpath, "-s")
     reprec.assertoutcome(skipped=1)
 
-def test_class_setup(testdir):
+def test_setup_setUpClass(testdir):
     testpath = testdir.makepyfile("""
         import unittest
         import pytest
@@ -104,6 +104,26 @@ def test_class_setup(testdir):
     reprec = testdir.inline_run(testpath)
     reprec.assertoutcome(passed=3)
 
+def test_setup_class(testdir):
+    testpath = testdir.makepyfile("""
+        import unittest
+        import pytest
+        class MyTestCase(unittest.TestCase):
+            x = 0
+            def setup_class(cls):
+                cls.x += 1
+            def test_func1(self):
+                assert self.x == 1
+            def test_func2(self):
+                assert self.x == 1
+            def teardown_class(cls):
+                cls.x -= 1
+        def test_teareddown():
+            assert MyTestCase.x == 0
+    """)
+    reprec = testdir.inline_run(testpath)
+    reprec.assertoutcome(passed=3)
+
 
 @pytest.mark.multi(type=['Error', 'Failure'])
 def test_testcase_adderrorandfailure_defers(testdir, type):

--- a/pytest.py
+++ b/pytest.py
@@ -5,7 +5,7 @@ see http://pytest.org for documentation 
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '2.0.0.dev35'
+__version__ = '2.0.0.dev36'
 __all__ = ['main']
 
 from _pytest.core import main, UsageError, _preloadplugins



More information about the pytest-commit mailing list