Add pytest CLI option `--fork` so that we can just run with specific phase (fork)

This commit is contained in:
Hsiao-Wei Wang 2021-10-18 17:42:47 +08:00
parent 6852c5a1d0
commit afb62eebf0
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E
2 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,7 @@
from eth2spec.test import context
from eth2spec.test.helpers.constants import (
ALL_PHASES,
)
from eth2spec.utils import bls as bls_utils
# We import pytest only when it's present, i.e. when we are running tests.
@ -29,6 +32,13 @@ def pytest_addoption(parser):
"--preset", action="store", type=str, default="minimal",
help="preset: make the pyspec use the specified preset"
)
parser.addoption(
"--fork", action="append", type=str,
help=(
"fork: make the pyspec only run with the specified phase."
" To run multiple phases, e.g., --fork=phase0 --fork=altair"
)
)
parser.addoption(
"--disable-bls", action="store_true", default=False,
help="bls-default: make tests that are not dependent on BLS run without BLS"
@ -44,6 +54,16 @@ def preset(request):
context.DEFAULT_TEST_PRESET = request.config.getoption("--preset")
@fixture(autouse=True)
def run_phases(request):
phases = request.config.getoption("--fork")
if phases:
phases = [phase.lower() for phase in phases]
context.DEFAULT_PYTEST_FORKS = set(phases)
else:
context.DEFAULT_PYTEST_FORKS = ALL_PHASES
@fixture(autouse=True)
def bls_default(request):
disable_bls = request.config.getoption("--disable-bls")

View File

@ -22,6 +22,9 @@ from lru import LRU
# Without pytest CLI arg or pyspec-test-generator 'preset' argument, this will be the config to apply.
DEFAULT_TEST_PRESET = MINIMAL
# Without pytest CLI arg or pyspec-test-generator 'run-phase' argument, this will be the config to apply.
DEFAULT_PYTEST_FORKS = ALL_PHASES
# TODO: currently phases are defined as python modules.
# It would be better if they would be more well-defined interfaces for stronger typing.
@ -351,7 +354,7 @@ def with_phases(phases, other_phases=None):
"""
def decorator(fn):
def wrapper(*args, **kw):
run_phases = phases
run_phases = set(phases).intersection(DEFAULT_PYTEST_FORKS)
# limit phases if one explicitly specified
if 'phase' in kw: