From 41e424b1729afb23a03a1708444f7bca1aa2481c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 27 Dec 2021 11:09:51 +0200 Subject: [PATCH] Merge pull request #9441 from bluetech/nose-setup-callable python: skip nose setup/teardown fixtures if non-callable (cherry picked from commit 7fc2cf51c22c0ec6b1599662d9069f620374873a) --- src/_pytest/python.py | 6 ++++++ testing/test_nose.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 8182d9a50..4f1590282 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -517,12 +517,18 @@ class Module(nodes.File, PyCollector): self.obj, ("setUpModule", "setup_module") ) 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",)) + if not callable(setup_module): + setup_module = None teardown_module = _get_first_non_fixture_func( self.obj, ("tearDownModule", "teardown_module") ) if teardown_module is None and has_nose: 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: return diff --git a/testing/test_nose.py b/testing/test_nose.py index edca0f446..1ded8854b 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -477,3 +477,22 @@ def test_raises(pytester: Pytester) -> None: "* 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