From 8e5efa7d6d8fa948f18204b3d133266c770a4699 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 23 Oct 2009 15:27:59 +0200 Subject: [PATCH] better tests for the nose plugin, support module level teardown --HG-- branch : trunk --- _py/test/plugin/pytest_nose.py | 3 ++- testing/pytest/plugin/test_pytest_nose.py | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/_py/test/plugin/pytest_nose.py b/_py/test/plugin/pytest_nose.py index 4ea8306d3..f7bfbfda0 100644 --- 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 diff --git a/testing/pytest/plugin/test_pytest_nose.py b/testing/pytest/plugin/test_pytest_nose.py index aba8f3cc6..bb8b80d5f 100644 --- 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(testdir): 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*", ])