From 9a1002d3191d56def21d8c4256184b8af2c9f695 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Wed, 15 Jan 2025 06:49:23 +0100 Subject: [PATCH] Speed up tests by avoiding recreating PluginManager --- src/ert/config/ert_config.py | 7 ++++--- src/everest/config/simulator_config.py | 6 ++++-- tests/ert/ui_tests/cli/run_cli.py | 4 +++- tests/ert/unit_tests/test_run_path_creation.py | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index ec79c576ec1..0c2c198af05 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -305,8 +305,9 @@ def with_plugins( forward_model_step_classes: list[type[ForwardModelStepPlugin]] | None = None, env_pr_fm_step: dict[str, dict[str, Any]] | None = None, ) -> type["ErtConfig"]: + pm = ErtPluginManager() if forward_model_step_classes is None: - forward_model_step_classes = ErtPluginManager().forward_model_steps + forward_model_step_classes = pm.forward_model_steps preinstalled_fm_steps: dict[str, ForwardModelStepPlugin] = {} for fm_step_subclass in forward_model_step_classes: @@ -315,7 +316,7 @@ def with_plugins( if env_pr_fm_step is None: env_pr_fm_step = _uppercase_subkeys_and_stringify_subvalues( - ErtPluginManager().get_forward_model_configuration() + pm.get_forward_model_configuration() ) class ErtConfigWithPlugins(ErtConfig): @@ -323,7 +324,7 @@ class ErtConfigWithPlugins(ErtConfig): dict[str, ForwardModelStepPlugin] ] = preinstalled_fm_steps ENV_PR_FM_STEP: ClassVar[dict[str, dict[str, Any]]] = env_pr_fm_step - ACTIVATE_SCRIPT = ErtPluginManager().activate_script() + ACTIVATE_SCRIPT = pm.activate_script() assert issubclass(ErtConfigWithPlugins, ErtConfig) return ErtConfigWithPlugins diff --git a/src/everest/config/simulator_config.py b/src/everest/config/simulator_config.py index 4991bc71bdb..7797dbd46a9 100644 --- a/src/everest/config/simulator_config.py +++ b/src/everest/config/simulator_config.py @@ -97,8 +97,10 @@ class SimulatorConfig(BaseModel, extra="forbid"): # type: ignore def default_local_queue(cls, v): if v is None: return LocalQueueOptions(max_running=8) - elif "activate_script" not in v and ErtPluginManager().activate_script(): - v["activate_script"] = ErtPluginManager().activate_script() + if "activate_script" not in v and ( + active_script := ErtPluginManager().activate_script() + ): + v["activate_script"] = active_script return v @model_validator(mode="before") diff --git a/tests/ert/ui_tests/cli/run_cli.py b/tests/ert/ui_tests/cli/run_cli.py index fe494d602e3..b8f28157323 100644 --- a/tests/ert/ui_tests/cli/run_cli.py +++ b/tests/ert/ui_tests/cli/run_cli.py @@ -5,6 +5,8 @@ from ert.cli.main import run_cli as cli_runner from ert.plugins import ErtPluginManager +PM = ErtPluginManager() + def run_cli(*args): parser = ArgumentParser(prog="test_main") @@ -15,7 +17,7 @@ def run_cli(*args): def run_cli_with_pm(args: list[Any], pm: ErtPluginManager | None = None): if pm is None: - pm = ErtPluginManager() + pm = PM parser = ArgumentParser(prog="test_main") parsed = ert_parser(parser, args) res = cli_runner(parsed, pm) diff --git a/tests/ert/unit_tests/test_run_path_creation.py b/tests/ert/unit_tests/test_run_path_creation.py index 356bd8c077a..f65b74acf59 100644 --- a/tests/ert/unit_tests/test_run_path_creation.py +++ b/tests/ert/unit_tests/test_run_path_creation.py @@ -430,7 +430,7 @@ def test_that_deprecated_runpath_substitution_remain_valid(make_run_path): def test_write_runpath_file(storage, itr, run_paths): runpath_fmt = "simulations//realization-/iter-" runpath_list_path = "a_file_name" - ert_config = ErtConfig.with_plugins().from_file_contents( + ert_config = ErtConfig.from_file_contents( dedent( f"""\ NUM_REALIZATIONS 25