File tree Expand file tree Collapse file tree 1 file changed +0
-42
lines changed
web3/_utils/module_testing Expand file tree Collapse file tree 1 file changed +0
-42
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
- import functools
3
- import pytest
4
2
from typing import (
5
3
TYPE_CHECKING ,
6
4
Any ,
7
- Callable ,
8
5
Collection ,
9
6
Dict ,
10
7
Generator ,
11
8
Literal ,
12
9
Sequence ,
13
- Tuple ,
14
- Type ,
15
10
Union ,
16
11
)
17
12
63
58
flaky_geth_dev_mining = flaky (max_runs = 3 , min_passes = 1 )
64
59
65
60
66
- def flaky_with_xfail_on_exception (
67
- reason : str ,
68
- exception : Union [Type [Exception ], Tuple [Type [Exception ], ...]],
69
- max_runs : int = 3 ,
70
- min_passes : int = 1 ,
71
- ) -> Callable [[Any ], Any ]:
72
- """
73
- Some tests inconsistently fail hard with a particular exception and retrying
74
- these tests often times does not get them "unstuck". If we've exhausted all flaky
75
- retries and this expected exception is raised, `xfail` the test with the given
76
- reason.
77
- """
78
- runs = max_runs
79
-
80
- def decorator (func : Any ) -> Any :
81
- @flaky (max_runs = max_runs , min_passes = min_passes )
82
- @functools .wraps (func )
83
- async def wrapper (self : Any , * args : Any , ** kwargs : Any ) -> Any :
84
- nonlocal runs
85
- try :
86
- return await func (self , * args , ** kwargs )
87
- except exception :
88
- # xfail the test only if the exception is raised and we have exhausted
89
- # all flaky retries
90
- if runs == 1 :
91
- pytest .xfail (reason )
92
- runs -= 1
93
- pytest .fail (f"xfailed but { runs } run(s) remaining with flaky..." )
94
- except Exception as e :
95
- # let flaky handle it
96
- raise e
97
-
98
- return wrapper
99
-
100
- return decorator
101
-
102
-
103
61
def assert_contains_log (
104
62
result : Sequence [LogReceipt ],
105
63
block_with_txn_with_log : BlockData ,
You can’t perform that action at this time.
0 commit comments