better tests for the nose plugin, support module level teardown
--HG-- branch : trunk
This commit is contained in:
parent
82caacd633
commit
8e5efa7d6d
|
@ -72,7 +72,8 @@ def pytest_runtest_setup(item):
|
||||||
|
|
||||||
def pytest_runtest_teardown(item):
|
def pytest_runtest_teardown(item):
|
||||||
if isinstance(item, py.test.collect.Function):
|
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'):
|
#if hasattr(item.parent, '_nosegensetup'):
|
||||||
# #call_optional(item._nosegensetup, 'teardown')
|
# #call_optional(item._nosegensetup, 'teardown')
|
||||||
# del item.parent._nosegensetup
|
# del item.parent._nosegensetup
|
||||||
|
|
|
@ -88,14 +88,30 @@ def test_nose_test_generator_fixtures(testdir):
|
||||||
|
|
||||||
def test_module_level_setup(testdir):
|
def test_module_level_setup(testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
from nose.tools import with_setup
|
||||||
items = {}
|
items = {}
|
||||||
def setup():
|
def setup():
|
||||||
items[1]=1
|
items[1]=1
|
||||||
|
|
||||||
def test_setup_changed_stuff():
|
def teardown():
|
||||||
assert items
|
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 = testdir.runpytest('-p', 'nose')
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*1 passed*",
|
"*2 passed*",
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in New Issue