Skip to content

refactor(consume): create explicit pytest plugin structure #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Users can select any of the artifacts depending on their testing needs for their
#### `consume`

- πŸ”€ `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)).
- πŸ”€ Refactor consume simulator architecture to use explicit pytest plugin structure with forward-looking architecture ([#1801](https://github.com/ethereum/execution-spec-tests/pull/1801)).

#### `execute`

Expand Down
6 changes: 3 additions & 3 deletions pytest-framework.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ addopts =
--ignore=src/pytest_plugins/consume/test_cache.py
--ignore=src/pytest_plugins/consume/direct/
--ignore=src/pytest_plugins/consume/direct/test_via_direct.py
--ignore=src/pytest_plugins/consume/hive_simulators/
--ignore=src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py
--ignore=src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py
--ignore=src/pytest_plugins/consume/simulators/
--ignore=src/pytest_plugins/consume/simulators/engine/test_via_engine.py
--ignore=src/pytest_plugins/consume/simulators/rlp/test_via_rlp.py
--ignore=src/pytest_plugins/execute/test_recover.py
2 changes: 1 addition & 1 deletion src/cli/extract_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ethereum_test_fixtures.file import Fixtures
from ethereum_test_fixtures.pre_alloc_groups import PreAllocGroup
from ethereum_test_forks import Fork
from pytest_plugins.consume.hive_simulators.ruleset import ruleset
from pytest_plugins.consume.simulators.helpers.ruleset import ruleset


def get_docker_containers() -> set[str]:
Expand Down
20 changes: 11 additions & 9 deletions src/cli/pytest_commands/consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
class ConsumeCommand(PytestCommand):
"""Pytest command for consume operations."""

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

if is_hive:
processors.extend(
[
HiveEnvironmentProcessor(),
HiveEnvironmentProcessor(command_name=command_name),
ConsumeCommandProcessor(is_hive=True),
]
)
Expand Down Expand Up @@ -54,13 +54,15 @@ def get_command_paths(command_name: str, is_hive: bool) -> List[Path]:
base_path = Path("src/pytest_plugins/consume")
if command_name == "hive":
commands = ["rlp", "engine"]
command_paths = [
base_path / "simulators" / "hive_tests" / f"test_via_{cmd}.py" for cmd in commands
]
elif command_name in ["engine", "rlp"]:
command_paths = [base_path / "simulators" / "hive_tests" / f"test_via_{command_name}.py"]
elif command_name == "direct":
command_paths = [base_path / "direct" / "test_via_direct.py"]
else:
commands = [command_name]

command_paths = [
base_path / ("hive_simulators" if is_hive else "") / cmd / f"test_via_{cmd}.py"
for cmd in commands
]
raise ValueError(f"Unexpected command: {command_name}.")
return command_paths


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

return command
Expand Down
12 changes: 10 additions & 2 deletions src/cli/pytest_commands/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def _is_writing_to_stdout(self, args: List[str]) -> bool:
class HiveEnvironmentProcessor(ArgumentProcessor):
"""Processes Hive environment variables for consume commands."""

def __init__(self, command_name: str):
"""Initialize the processor with command name to determine plugin."""
self.command_name = command_name

def process_args(self, args: List[str]) -> List[str]:
"""Convert hive environment variables into pytest flags."""
modified_args = args[:]
Expand All @@ -92,8 +96,12 @@ def process_args(self, args: List[str]) -> List[str]:
if os.getenv("HIVE_LOGLEVEL") is not None:
warnings.warn("HIVE_LOG_LEVEL is not yet supported.", stacklevel=2)

modified_args.extend(["-p", "pytest_plugins.pytest_hive.pytest_hive"])

if self.command_name == "engine":
modified_args.extend(["-p", "pytest_plugins.consume.simulators.engine.conftest"])
elif self.command_name == "rlp":
modified_args.extend(["-p", "pytest_plugins.consume.simulators.rlp.conftest"])
else:
raise ValueError(f"Unknown command name: {self.command_name}")
return modified_args

def _has_regex_or_sim_limit(self, args: List[str]) -> bool:
Expand Down
Loading
Loading