@@ -48,7 +48,7 @@ def pytest_addoption(parser):
48
48
dest = "disable_strict_exception_matching" ,
49
49
default = "" ,
50
50
help = (
51
- "Comma-separated list of the names of clients which should NOT use strict "
51
+ "Comma-separated list of client names and/or forks which should NOT use strict "
52
52
"exception matching."
53
53
),
54
54
)
@@ -208,20 +208,31 @@ def buffered_genesis(client_genesis: dict) -> io.BufferedReader:
208
208
return io .BufferedReader (cast (io .RawIOBase , io .BytesIO (genesis_bytes )))
209
209
210
210
211
+ @pytest .fixture (scope = "session" )
212
+ def client_exception_mapper_cache ():
213
+ """Cache for exception mappers by client type."""
214
+ return {}
215
+
216
+
211
217
@pytest .fixture (scope = "function" )
212
218
def client_exception_mapper (
213
- client_type : ClientType ,
219
+ client_type : ClientType , client_exception_mapper_cache
214
220
) -> ExceptionMapper | None :
215
- """Return the exception mapper for the client type."""
216
- for client in EXCEPTION_MAPPERS :
217
- if client in client_type .name :
218
- return EXCEPTION_MAPPERS [client ]
219
- return None
221
+ """Return the exception mapper for the client type, with caching."""
222
+ if client_type .name not in client_exception_mapper_cache :
223
+ for client in EXCEPTION_MAPPERS :
224
+ if client in client_type .name :
225
+ client_exception_mapper_cache [client_type .name ] = EXCEPTION_MAPPERS [client ]
226
+ break
227
+ else :
228
+ client_exception_mapper_cache [client_type .name ] = None
229
+
230
+ return client_exception_mapper_cache [client_type .name ]
220
231
221
232
222
233
@pytest .fixture (scope = "session" )
223
234
def disable_strict_exception_matching (request : pytest .FixtureRequest ) -> List [str ]:
224
- """Return the list of clients that should NOT use strict exception matching."""
235
+ """Return the list of clients or forks that should NOT use strict exception matching."""
225
236
config_string = request .config .getoption ("disable_strict_exception_matching" )
226
237
return config_string .split ("," ) if config_string else []
227
238
@@ -232,7 +243,30 @@ def client_strict_exception_matching(
232
243
disable_strict_exception_matching : List [str ],
233
244
) -> bool :
234
245
"""Return True if the client type should use strict exception matching."""
235
- return not any (client in client_type .name for client in disable_strict_exception_matching )
246
+ return not any (
247
+ client .lower () in client_type .name .lower () for client in disable_strict_exception_matching
248
+ )
249
+
250
+
251
+ @pytest .fixture (scope = "function" )
252
+ def fork_strict_exception_matching (
253
+ fixture : BlockchainFixtureCommon ,
254
+ disable_strict_exception_matching : List [str ],
255
+ ) -> bool :
256
+ """Return True if the fork should use strict exception matching."""
257
+ # NOTE: `in` makes it easier for transition forks ("Prague" in "CancunToPragueAtTime15k")
258
+ return not any (
259
+ fork .lower () in fixture .fork .lower () for fork in disable_strict_exception_matching
260
+ )
261
+
262
+
263
+ @pytest .fixture (scope = "function" )
264
+ def strict_exception_matching (
265
+ client_strict_exception_matching : bool ,
266
+ fork_strict_exception_matching : bool ,
267
+ ) -> bool :
268
+ """Return True if the test should use strict exception matching."""
269
+ return client_strict_exception_matching and fork_strict_exception_matching
236
270
237
271
238
272
@pytest .fixture (scope = "function" )
0 commit comments