diff --git a/_py/test/plugin/pytest_nose.py b/_py/test/plugin/pytest_nose.py index bc46e6caa..4ea8306d3 100644 --- a/_py/test/plugin/pytest_nose.py +++ b/_py/test/plugin/pytest_nose.py @@ -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 diff --git a/testing/pytest/plugin/test_pytest_nose.py b/testing/pytest/plugin/test_pytest_nose.py index 4950095dd..aba8f3cc6 100644 --- a/testing/pytest/plugin/test_pytest_nose.py +++ b/testing/pytest/plugin/test_pytest_nose.py @@ -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*", + ])