From 13cdfa8edb748d2d108fcb8bafdcb7e73888b63b Mon Sep 17 00:00:00 2001 From: protolambda Date: Sat, 4 Jan 2020 18:33:15 +0100 Subject: [PATCH] apply configs in tests properly --- test_libs/pyspec/eth2spec/config/apply_config.py | 3 +++ test_libs/pyspec/eth2spec/test/conftest.py | 3 +++ test_libs/pyspec/eth2spec/test/context.py | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test_libs/pyspec/eth2spec/config/apply_config.py b/test_libs/pyspec/eth2spec/config/apply_config.py index 768abba64..2f0ce5902 100644 --- a/test_libs/pyspec/eth2spec/config/apply_config.py +++ b/test_libs/pyspec/eth2spec/config/apply_config.py @@ -5,6 +5,7 @@ presets: Dict[str, Any] = {} # Access to overwrite spec constants based on configuration +# This is called by the spec module after declaring its globals, and applies the loaded presets. def apply_constants_preset(spec_globals: Dict[str, Any]) -> None: global presets for k, v in presets.items(): @@ -14,6 +15,8 @@ def apply_constants_preset(spec_globals: Dict[str, Any]) -> None: spec_globals[k] = v +# Load presets from a file. This does not apply the presets. +# To apply the presets, reload the spec module (it will re-initialize with the presets taken from here). def load_presets(configs_path, config_name): global presets presets = loader.load_presets(configs_path, config_name) diff --git a/test_libs/pyspec/eth2spec/test/conftest.py b/test_libs/pyspec/eth2spec/test/conftest.py index a0a200f0b..35ffb3cb8 100644 --- a/test_libs/pyspec/eth2spec/test/conftest.py +++ b/test_libs/pyspec/eth2spec/test/conftest.py @@ -1,4 +1,5 @@ from eth2spec.config import apply_config +from eth2spec.test.context import reload_specs # We import pytest only when it's present, i.e. when we are running tests. # The test-cases themselves can be generated without installing pytest. @@ -33,3 +34,5 @@ def pytest_addoption(parser): def config(request): config_name = request.config.getoption("--config") apply_config.load_presets('../../configs/', config_name) + # now that the presets are loaded, reload the specs to apply them + reload_specs() diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index 0fb46aa50..195d1e5fa 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -10,8 +10,10 @@ from typing import Any, Callable, Sequence from importlib import reload -reload(spec_phase0) -reload(spec_phase1) + +def reload_specs(): + reload(spec_phase0) + reload(spec_phase1) def with_custom_state(balances_fn: Callable[[Any], Sequence[int]],