[py-svn] py-trunk commit 61a03e7e7224: better tests for the nose plugin, support module level teardown

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Oct 27 16:52:31 CET 2009


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
# Date 1256304479 -7200
# Node ID 61a03e7e72248ee42f29cbceea1aad052c62362b
# Parent eb41af2b863412a2d9d0e73d42d4f13407ef120e
better tests for the nose plugin, support module level teardown

--- a/_py/test/plugin/pytest_nose.py
+++ b/_py/test/plugin/pytest_nose.py
@@ -72,7 +72,8 @@ def pytest_runtest_setup(item):
 
 def pytest_runtest_teardown(item):
     if isinstance(item, py.test.collect.Function):
-        call_optional(item.obj, 'teardown')
+        if not call_optional(item.obj, 'teardown'):
+            call_optional(item.parent.obj, 'teardown')
         #if hasattr(item.parent, '_nosegensetup'):
         #    #call_optional(item._nosegensetup, 'teardown')
         #    del item.parent._nosegensetup

--- a/testing/pytest/plugin/test_pytest_nose.py
+++ b/testing/pytest/plugin/test_pytest_nose.py
@@ -88,14 +88,30 @@ def test_nose_test_generator_fixtures(te
 
 def test_module_level_setup(testdir):
     testdir.makepyfile("""
+        from nose.tools import with_setup
         items = {}
         def setup():
             items[1]=1
 
-        def test_setup_changed_stuff():
-            assert items
+        def teardown():
+            del items[1]
+
+        def setup2():
+            items[2] = 2
+
+        def teardown2():
+            del items[2]
+
+        def test_setup_module_setup():
+            assert items[1] == 1
+
+        @with_setup(setup2, teardown2)
+        def test_local_setup():
+            assert items[2] == 2
+            assert 1 not in items
+
     """)
     result = testdir.runpytest('-p', 'nose')
     result.stdout.fnmatch_lines([
-        "*1 passed*",
+        "*2 passed*",
     ])



More information about the pytest-commit mailing list