Skip to content

Commit 00aa6a6

Browse files
committed
refactor(consume): split into separate plugins by functionality
1 parent 5a7bb7c commit 00aa6a6

File tree

6 files changed

+323
-275
lines changed

6 files changed

+323
-275
lines changed

src/pytest_plugins/consume/simulators/engine/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
from ethereum_test_fixtures import BlockchainEngineFixture
1515
from ethereum_test_rpc import EngineRPC
1616

17-
pytest_plugins = "pytest_plugins.consume.simulators.single_test_client"
17+
pytest_plugins = (
18+
"pytest_plugins.consume.simulators.single_test_client",
19+
"pytest_plugins.consume.simulators.test_case_description",
20+
"pytest_plugins.consume.simulators.timing_data",
21+
"pytest_plugins.consume.simulators.exceptions",
22+
)
1823

1924

2025
def pytest_configure(config):
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Pytest plugin that defines options and fixtures for client exceptions."""
2+
3+
from typing import List
4+
5+
import pytest
6+
from hive.client import ClientType
7+
8+
from ethereum_test_exceptions import ExceptionMapper
9+
from ethereum_test_fixtures import (
10+
BlockchainFixtureCommon,
11+
)
12+
13+
from .helpers.exceptions import EXCEPTION_MAPPERS
14+
15+
16+
def pytest_addoption(parser):
17+
"""Hive simulator specific consume command line options."""
18+
consume_group = parser.getgroup(
19+
"consume", "Arguments related to consuming fixtures via a client"
20+
)
21+
consume_group.addoption(
22+
"--disable-strict-exception-matching",
23+
action="store",
24+
dest="disable_strict_exception_matching",
25+
default="",
26+
help=(
27+
"Comma-separated list of client names and/or forks which should NOT use strict "
28+
"exception matching."
29+
),
30+
)
31+
32+
33+
@pytest.fixture(scope="session")
34+
def client_exception_mapper_cache():
35+
"""Cache for exception mappers by client type."""
36+
return {}
37+
38+
39+
@pytest.fixture(scope="function")
40+
def client_exception_mapper(
41+
client_type: ClientType, client_exception_mapper_cache
42+
) -> ExceptionMapper | None:
43+
"""Return the exception mapper for the client type, with caching."""
44+
if client_type.name not in client_exception_mapper_cache:
45+
for client in EXCEPTION_MAPPERS:
46+
if client in client_type.name:
47+
client_exception_mapper_cache[client_type.name] = EXCEPTION_MAPPERS[client]
48+
break
49+
else:
50+
client_exception_mapper_cache[client_type.name] = None
51+
52+
return client_exception_mapper_cache[client_type.name]
53+
54+
55+
@pytest.fixture(scope="session")
56+
def disable_strict_exception_matching(request: pytest.FixtureRequest) -> List[str]:
57+
"""Return the list of clients or forks that should NOT use strict exception matching."""
58+
config_string = request.config.getoption("disable_strict_exception_matching")
59+
return config_string.split(",") if config_string else []
60+
61+
62+
@pytest.fixture(scope="function")
63+
def client_strict_exception_matching(
64+
client_type: ClientType,
65+
disable_strict_exception_matching: List[str],
66+
) -> bool:
67+
"""Return True if the client type should use strict exception matching."""
68+
return not any(
69+
client.lower() in client_type.name.lower() for client in disable_strict_exception_matching
70+
)
71+
72+
73+
@pytest.fixture(scope="function")
74+
def fork_strict_exception_matching(
75+
fixture: BlockchainFixtureCommon,
76+
disable_strict_exception_matching: List[str],
77+
) -> bool:
78+
"""Return True if the fork should use strict exception matching."""
79+
# NOTE: `in` makes it easier for transition forks ("Prague" in "CancunToPragueAtTime15k")
80+
return not any(
81+
s.lower() in str(fixture.fork).lower() for s in disable_strict_exception_matching
82+
)
83+
84+
85+
@pytest.fixture(scope="function")
86+
def strict_exception_matching(
87+
client_strict_exception_matching: bool,
88+
fork_strict_exception_matching: bool,
89+
) -> bool:
90+
"""Return True if the test should use strict exception matching."""
91+
return client_strict_exception_matching and fork_strict_exception_matching

src/pytest_plugins/consume/simulators/rlp/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
TestCase = TestCaseIndexFile | TestCaseStream
1313

14-
pytest_plugins = "pytest_plugins.consume.simulators.single_test_client"
14+
pytest_plugins = (
15+
"pytest_plugins.consume.simulators.single_test_client",
16+
"pytest_plugins.consume.simulators.test_case_description",
17+
"pytest_plugins.consume.simulators.timing_data",
18+
"pytest_plugins.consume.simulators.exceptions",
19+
)
1520

1621

1722
def pytest_configure(config):

0 commit comments

Comments
 (0)