From 0c3853e95952b61ce64f05a651f0e32b858f15ad Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Sun, 11 Dec 2022 23:41:08 +0100 Subject: [PATCH] Avoid modifying caller `phases` (`kw` is shallow copy) --- tests/core/pyspec/eth2spec/test/context.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index d80d841cc..b1f608d7b 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -604,20 +604,26 @@ def with_config_overrides(config_overrides, emitted_fork=None, emit=True): """ def decorator(fn): def wrapper(*args, spec: Spec, **kw): + # Apply config overrides to spec spec, output_config = spec_with_config_overrides(_get_copy_of_spec(spec), config_overrides) - if emit and emitted_fork is None: - yield 'config', 'cfg', output_config + # Apply config overrides to additional phases, if present if 'phases' in kw: + phases = {} for fork in kw['phases']: - if is_post_fork(fork, spec.fork): - kw['phases'][fork], output_config = \ - spec_with_config_overrides(_get_copy_of_spec(kw['phases'][fork]), config_overrides) - if emit and emitted_fork == fork: - yield 'config', 'cfg', output_config + phases[fork], output = \ + spec_with_config_overrides(_get_copy_of_spec(kw['phases'][fork]), config_overrides) + if emitted_fork == fork: + output_config = output + kw['phases'] = phases # Run the function out = fn(*args, spec=spec, **kw) + + # Emit requested spec (with overrides) + if emit: + yield 'config', 'cfg', output_config + # If it's not returning None like a normal test function, # it's generating things, and we need to complete it before setting back the config. if out is not None: