22from _pytest import python
33from _pytest import unittest
44from _pytest .config import hookimpl
5+ from _pytest .fixtures import getfixturemarker
56from _pytest .nodes import Item
67
78
89@hookimpl (trylast = True )
9- def pytest_runtest_setup (item ):
10+ def pytest_runtest_setup (item ) -> None :
1011 if is_potential_nosetest (item ):
1112 if not call_optional (item .obj , "setup" ):
1213 # Call module level setup if there is no object level one.
@@ -15,7 +16,7 @@ def pytest_runtest_setup(item):
1516 item .session ._setupstate .addfinalizer ((lambda : teardown_nose (item )), item )
1617
1718
18- def teardown_nose (item ):
19+ def teardown_nose (item ) -> None :
1920 if is_potential_nosetest (item ):
2021 if not call_optional (item .obj , "teardown" ):
2122 call_optional (item .parent .obj , "teardown" )
@@ -29,11 +30,16 @@ def is_potential_nosetest(item: Item) -> bool:
2930 )
3031
3132
32- def call_optional (obj , name ) :
33+ def call_optional (obj : object , name : str ) -> bool :
3334 method = getattr (obj , name , None )
34- isfixture = hasattr (method , "_pytestfixturefunction" )
35- if method is not None and not isfixture and callable (method ):
36- # If there's any problems allow the exception to raise rather than
37- # silently ignoring them.
38- method ()
39- return True
35+ if method is None :
36+ return False
37+ is_fixture = getfixturemarker (method ) is not None
38+ if is_fixture :
39+ return False
40+ if not callable (method ):
41+ return False
42+ # If there are any problems allow the exception to raise rather than
43+ # silently ignoring it.
44+ method ()
45+ return True
0 commit comments