4
4
import types
5
5
from collections import defaultdict
6
6
import pytest
7
+ try :
8
+ from pytest_rerunfailures import get_reruns_count
9
+ except ImportError :
10
+ get_reruns_count = None
7
11
8
12
9
13
PY3 = sys .version_info [0 ] == 3
@@ -22,6 +26,24 @@ def pytest_runtest_setup(item):
22
26
)
23
27
24
28
29
+ def pytest_runtest_teardown (item , nextitem ):
30
+ """ Add support for the pytest-rerunfailures plugin"""
31
+ if get_reruns_count :
32
+ reruns = get_reruns_count (item )
33
+ if reruns is None :
34
+ return
35
+ if not hasattr (item , "execution_count" ):
36
+ # pytest_runtest_protocol hook of this plugin was not executed
37
+ # -> teardown needs to be skipped as well
38
+ return
39
+ if item .execution_count <= reruns and any (item ._test_failed_statuses .values ()):
40
+ # remove any resolved lazy fixtures
41
+ if hasattr (item , "callspec" ):
42
+ for key , value in item .callspec .params .items ():
43
+ if item .stash .get (key , None ) and item .stash [key ]["is_lazy_fixture" ]:
44
+ item .callspec .params [key ] = lazy_fixture (item .stash [key ]["name" ])
45
+
46
+
25
47
def fillfixtures (_fillfixtures ):
26
48
def fill (request ):
27
49
item = request ._pyfuncitem
@@ -33,6 +55,8 @@ def fill(request):
33
55
for param , val in sorted_by_dependency (item .callspec .params , fixturenames ):
34
56
if val is not None and is_lazy_fixture (val ):
35
57
item .callspec .params [param ] = request .getfixturevalue (val .name )
58
+ # stash the fixture value in the item, so it can be used as a backref
59
+ item .stash [param ] = {'is_lazy_fixture' : True , "name" : val .name }
36
60
elif param not in item .funcargs :
37
61
item .funcargs [param ] = request .getfixturevalue (param )
38
62
0 commit comments