nosetest plugin now supports fallback to module level setup

--HG--
branch : trunk
This commit is contained in:
Ronny Pfannschmidt 2009-10-23 15:11:53 +02:00
parent 861f34fe90
commit 82caacd633
2 changed files with 20 additions and 1 deletions

View File

@ -66,7 +66,9 @@ def pytest_runtest_setup(item):
if isinstance(gen.parent, py.test.collect.Instance):
call_optional(gen.parent.obj, 'setup')
gen._nosegensetup = True
call_optional(item.obj, 'setup')
if not call_optional(item.obj, 'setup'):
# call module level setup if there is no object level one
call_optional(item.parent.obj, 'setup')
def pytest_runtest_teardown(item):
if isinstance(item, py.test.collect.Function):
@ -83,3 +85,6 @@ def call_optional(obj, name):
method = getattr(obj, name, None)
if method:
method()
return True
else:
return False

View File

@ -85,3 +85,17 @@ def test_nose_test_generator_fixtures(testdir):
])
def test_module_level_setup(testdir):
testdir.makepyfile("""
items = {}
def setup():
items[1]=1
def test_setup_changed_stuff():
assert items
""")
result = testdir.runpytest('-p', 'nose')
result.stdout.fnmatch_lines([
"*1 passed*",
])