Skip to content

Commit 1817346

Browse files
authored
refactor(consume): create explicit pytest plugin structure (#1801)
* refactor(consume): rename `hive_simulators` to `simulators`. * refactor(consume): move helper modules to a new `helpers` sub-package * refactor(consume): rename `conftest` to `single_test_client` plugin Plugins called 'conftest' are registered automatically if in a sub-path to a test. This rename requires an explicit registration, which is specified by defining the `pytest_plugins` variable in 'engine/conftest.py', respectively, 'rlp/conftest.py'. * refactor(consume): split into separate plugins by functionality * refactor(consume): split base functionality out to the `base` plugin These are fixtures that can also be shared by multi-client architecture simulators. * fix(consume): add `genesis_header` to `single_test_cilent` plugin * refactor(consume): move test execution files to shared hive_tests directory Consolidate test_via_engine.py and test_via_rlp.py into a shared hive_tests/ directory to improve organization and prepare for future multi-client architectures. - Create src/pytest_plugins/consume/simulators/hive_tests/ directory. - Move test_via_engine.py from engine/ to hive_tests/. - Move test_via_rlp.py from rlp/ to hive_tests/. - Update get_command_paths() to reference new locations. - Maintain separation: plugin configs (conftest.py) stay with their simulators. This provides better logical organization of test execution files while maintaining explicit pytest plugin structure. * fix(consume): add explicit plugin registration for simulator-specific configs With the move to hive_tests/, the simulator-specific conftest.py files are no longer automatically discovered. Add explicit plugin registration to ensure _supported_fixture_formats and other simulator configs are properly loaded. - Add command_name parameter to HiveEnvironmentProcessor. - Register simulator-specific plugins based on command name. - Update ConsumeCommand to pass command_name to processors. - Fix AttributeError: 'Config' object has no attribute '_supported_fixture_formats'. * docs: add changelog entry for consume simulator refactor (#1801) * refactor(consume): move pytest_hive plugin registration to simulator conftest files Move pytest_hive plugin registration from HiveEnvironmentProcessor to individual simulator conftest files to centralize all plugin configuration in one place per simulator. * chore(cli): remove verbose docstring to keep reviewers happy
1 parent 6ee9787 commit 1817346

24 files changed

+535
-450
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Users can select any of the artifacts depending on their testing needs for their
4242
#### `consume`
4343

4444
- 🔀 `consume` now automatically avoids GitHub API calls when using direct release URLs (better for CI environments), while release specifiers like `stable@latest` continue to use the API for version resolution ([#1788](https://github.com/ethereum/execution-spec-tests/pull/1788)).
45+
- 🔀 Refactor consume simulator architecture to use explicit pytest plugin structure with forward-looking architecture ([#1801](https://github.com/ethereum/execution-spec-tests/pull/1801)).
4546

4647
#### `execute`
4748

pytest-framework.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ addopts =
1313
--ignore=src/pytest_plugins/consume/test_cache.py
1414
--ignore=src/pytest_plugins/consume/direct/
1515
--ignore=src/pytest_plugins/consume/direct/test_via_direct.py
16-
--ignore=src/pytest_plugins/consume/hive_simulators/
17-
--ignore=src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py
18-
--ignore=src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py
16+
--ignore=src/pytest_plugins/consume/simulators/
17+
--ignore=src/pytest_plugins/consume/simulators/engine/test_via_engine.py
18+
--ignore=src/pytest_plugins/consume/simulators/rlp/test_via_rlp.py
1919
--ignore=src/pytest_plugins/execute/test_recover.py

src/cli/extract_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ethereum_test_fixtures.file import Fixtures
2424
from ethereum_test_fixtures.pre_alloc_groups import PreAllocGroup
2525
from ethereum_test_forks import Fork
26-
from pytest_plugins.consume.hive_simulators.ruleset import ruleset
26+
from pytest_plugins.consume.simulators.helpers.ruleset import ruleset
2727

2828

2929
def get_docker_containers() -> set[str]:

src/cli/pytest_commands/consume.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
class ConsumeCommand(PytestCommand):
1414
"""Pytest command for consume operations."""
1515

16-
def __init__(self, command_paths: List[Path], is_hive: bool = False):
16+
def __init__(self, command_paths: List[Path], is_hive: bool = False, command_name: str = ""):
1717
"""Initialize consume command with paths and processors."""
1818
processors: List[ArgumentProcessor] = [HelpFlagsProcessor("consume")]
1919

2020
if is_hive:
2121
processors.extend(
2222
[
23-
HiveEnvironmentProcessor(),
23+
HiveEnvironmentProcessor(command_name=command_name),
2424
ConsumeCommandProcessor(is_hive=True),
2525
]
2626
)
@@ -54,13 +54,15 @@ def get_command_paths(command_name: str, is_hive: bool) -> List[Path]:
5454
base_path = Path("src/pytest_plugins/consume")
5555
if command_name == "hive":
5656
commands = ["rlp", "engine"]
57+
command_paths = [
58+
base_path / "simulators" / "hive_tests" / f"test_via_{cmd}.py" for cmd in commands
59+
]
60+
elif command_name in ["engine", "rlp"]:
61+
command_paths = [base_path / "simulators" / "hive_tests" / f"test_via_{command_name}.py"]
62+
elif command_name == "direct":
63+
command_paths = [base_path / "direct" / "test_via_direct.py"]
5764
else:
58-
commands = [command_name]
59-
60-
command_paths = [
61-
base_path / ("hive_simulators" if is_hive else "") / cmd / f"test_via_{cmd}.py"
62-
for cmd in commands
63-
]
65+
raise ValueError(f"Unexpected command: {command_name}.")
6466
return command_paths
6567

6668

@@ -86,7 +88,7 @@ def decorator(func: Callable[..., Any]) -> click.Command:
8688
@common_pytest_options
8789
@functools.wraps(func)
8890
def command(pytest_args: List[str], **kwargs) -> None:
89-
consume_cmd = ConsumeCommand(command_paths, is_hive)
91+
consume_cmd = ConsumeCommand(command_paths, is_hive, command_name)
9092
consume_cmd.execute(list(pytest_args))
9193

9294
return command

src/cli/pytest_commands/processors.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def _is_writing_to_stdout(self, args: List[str]) -> bool:
7474
class HiveEnvironmentProcessor(ArgumentProcessor):
7575
"""Processes Hive environment variables for consume commands."""
7676

77+
def __init__(self, command_name: str):
78+
"""Initialize the processor with command name to determine plugin."""
79+
self.command_name = command_name
80+
7781
def process_args(self, args: List[str]) -> List[str]:
7882
"""Convert hive environment variables into pytest flags."""
7983
modified_args = args[:]
@@ -92,8 +96,12 @@ def process_args(self, args: List[str]) -> List[str]:
9296
if os.getenv("HIVE_LOGLEVEL") is not None:
9397
warnings.warn("HIVE_LOG_LEVEL is not yet supported.", stacklevel=2)
9498

95-
modified_args.extend(["-p", "pytest_plugins.pytest_hive.pytest_hive"])
96-
99+
if self.command_name == "engine":
100+
modified_args.extend(["-p", "pytest_plugins.consume.simulators.engine.conftest"])
101+
elif self.command_name == "rlp":
102+
modified_args.extend(["-p", "pytest_plugins.consume.simulators.rlp.conftest"])
103+
else:
104+
raise ValueError(f"Unknown command name: {self.command_name}")
97105
return modified_args
98106

99107
def _has_regex_or_sim_limit(self, args: List[str]) -> bool:

0 commit comments

Comments
 (0)