From cb513aa82d19feb81a85915df33b290df1be595d Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 21 Oct 2021 11:37:02 +0800 Subject: [PATCH] --fork cli option: fix the case of unset directory path + validate fork name --- tests/core/pyspec/eth2spec/test/conftest.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/conftest.py b/tests/core/pyspec/eth2spec/test/conftest.py index 55613be0a..751d4d3f1 100644 --- a/tests/core/pyspec/eth2spec/test/conftest.py +++ b/tests/core/pyspec/eth2spec/test/conftest.py @@ -49,6 +49,15 @@ def pytest_addoption(parser): ) +def _validate_fork_name(forks): + for fork in forks: + if fork not in ALL_PHASES: + raise ValueError( + f'The given --fork argument "{fork}" is not an available fork.' + f' The available forks: {ALL_PHASES}' + ) + + @fixture(autouse=True) def preset(request): context.DEFAULT_TEST_PRESET = request.config.getoption("--preset") @@ -56,10 +65,11 @@ def preset(request): @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) + forks = request.config.getoption("--fork", default=None) + if forks: + forks = [phase.lower() for phase in forks] + _validate_fork_name(forks) + context.DEFAULT_PYTEST_FORKS = set(forks) else: context.DEFAULT_PYTEST_FORKS = ALL_PHASES