From 8401331cfa6a4a9ce0efdb941d217354986913fd Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Tue, 17 Sep 2024 09:25:26 +0200 Subject: [PATCH] Move run_args and run_paths fixtures to unit_tests --- tests/conftest.py | 39 +---------------------------------- tests/unit_tests/conftest.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c3757c41473..c9b5742ce62 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,14 +6,11 @@ import sys from argparse import ArgumentParser from pathlib import Path -from typing import List, Optional from unittest.mock import MagicMock from qtpy.QtWidgets import QApplication from _ert.threading import set_signal_handler -from ert.run_arg import RunArg, create_run_arguments -from ert.runpaths import Runpaths if sys.version_info >= (3, 9): from importlib.resources import files @@ -32,7 +29,7 @@ from ert.ensemble_evaluator.config import EvaluatorServerConfig from ert.mode_definitions import ENSEMBLE_EXPERIMENT_MODE, ES_MDA_MODE from ert.services import StorageService -from ert.storage import Ensemble, open_storage +from ert.storage import open_storage from .utils import SOURCE_DIR @@ -480,37 +477,3 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) monkeypatch.setattr("ert.cli.main.EvaluatorServerConfig", MockESConfig) - - -@pytest.fixture -def run_paths(): - def func(ert_config: ErtConfig): - return Runpaths( - jobname_format=ert_config.model_config.jobname_format_string, - runpath_format=ert_config.model_config.runpath_format_string, - filename=str(ert_config.runpath_file), - substitution_list=ert_config.substitution_list, - ) - - yield func - - -@pytest.fixture -def run_args(run_paths): - def func( - ert_config: ErtConfig, - ensemble: Ensemble, - active_realizations: Optional[int] = None, - ) -> List[RunArg]: - active_realizations = ( - ert_config.model_config.num_realizations - if active_realizations is None - else active_realizations - ) - return create_run_arguments( - run_paths(ert_config), - [True] * active_realizations, - ensemble, - ) - - yield func diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 51b983760e8..0bc4c9dac6a 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -1,8 +1,14 @@ import os import sys +from typing import List, Optional import pytest +from ert.config import ErtConfig +from ert.run_arg import RunArg, create_run_arguments +from ert.runpaths import Runpaths +from ert.storage import Ensemble + @pytest.fixture(scope="session", autouse=True) def ensure_bin_in_path(): @@ -26,3 +32,37 @@ def snake_oil_field_example(setup_case): def prior_ensemble(storage): experiment_id = storage.create_experiment() return storage.create_ensemble(experiment_id, name="prior", ensemble_size=100) + + +@pytest.fixture +def run_paths(): + def func(ert_config: ErtConfig): + return Runpaths( + jobname_format=ert_config.model_config.jobname_format_string, + runpath_format=ert_config.model_config.runpath_format_string, + filename=str(ert_config.runpath_file), + substitution_list=ert_config.substitution_list, + ) + + yield func + + +@pytest.fixture +def run_args(run_paths): + def func( + ert_config: ErtConfig, + ensemble: Ensemble, + active_realizations: Optional[int] = None, + ) -> List[RunArg]: + active_realizations = ( + ert_config.model_config.num_realizations + if active_realizations is None + else active_realizations + ) + return create_run_arguments( + run_paths(ert_config), + [True] * active_realizations, + ensemble, + ) + + yield func