2
2
from _pytest import python
3
3
from _pytest import unittest
4
4
from _pytest .config import hookimpl
5
+ from _pytest .fixtures import getfixturemarker
5
6
from _pytest .nodes import Item
6
7
7
8
8
9
@hookimpl (trylast = True )
9
- def pytest_runtest_setup (item ):
10
+ def pytest_runtest_setup (item ) -> None :
10
11
if is_potential_nosetest (item ):
11
12
if not call_optional (item .obj , "setup" ):
12
13
# Call module level setup if there is no object level one.
@@ -15,7 +16,7 @@ def pytest_runtest_setup(item):
15
16
item .session ._setupstate .addfinalizer ((lambda : teardown_nose (item )), item )
16
17
17
18
18
- def teardown_nose (item ):
19
+ def teardown_nose (item ) -> None :
19
20
if is_potential_nosetest (item ):
20
21
if not call_optional (item .obj , "teardown" ):
21
22
call_optional (item .parent .obj , "teardown" )
@@ -29,11 +30,16 @@ def is_potential_nosetest(item: Item) -> bool:
29
30
)
30
31
31
32
32
- def call_optional (obj , name ) :
33
+ def call_optional (obj : object , name : str ) -> bool :
33
34
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