Merge pull request #9441 from bluetech/nose-setup-callable

python: skip nose setup/teardown fixtures if non-callable
This commit is contained in:
Ran Benita 2021-12-27 11:09:51 +02:00 committed by GitHub
commit 7fc2cf51c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -522,12 +522,18 @@ class Module(nodes.File, PyCollector):
self.obj, ("setUpModule", "setup_module") self.obj, ("setUpModule", "setup_module")
) )
if setup_module is None and has_nose: if setup_module is None and has_nose:
# The name "setup" is too common - only treat as fixture if callable.
setup_module = _get_first_non_fixture_func(self.obj, ("setup",)) setup_module = _get_first_non_fixture_func(self.obj, ("setup",))
if not callable(setup_module):
setup_module = None
teardown_module = _get_first_non_fixture_func( teardown_module = _get_first_non_fixture_func(
self.obj, ("tearDownModule", "teardown_module") self.obj, ("tearDownModule", "teardown_module")
) )
if teardown_module is None and has_nose: if teardown_module is None and has_nose:
teardown_module = _get_first_non_fixture_func(self.obj, ("teardown",)) teardown_module = _get_first_non_fixture_func(self.obj, ("teardown",))
# Same as "setup" above - only treat as fixture if callable.
if not callable(teardown_module):
teardown_module = None
if setup_module is None and teardown_module is None: if setup_module is None and teardown_module is None:
return return

View File

@ -477,3 +477,22 @@ def test_raises(pytester: Pytester) -> None:
"* 1 failed, 2 passed *", "* 1 failed, 2 passed *",
] ]
) )
def test_nose_setup_skipped_if_non_callable(pytester: Pytester) -> None:
"""Regression test for #9391."""
p = pytester.makepyfile(
__init__="",
setup="""
""",
teardown="""
""",
test_it="""
from . import setup, teardown
def test_it():
pass
""",
)
result = pytester.runpytest(p, "-p", "nose")
assert result.ret == 0