Skip to content

Commit d3ac331

Browse files
committed
ENH: Make ERT stop if CREATE_CASE_METADATA fails
1 parent 0f29f9d commit d3ac331

3 files changed

Lines changed: 854 additions & 761 deletions

File tree

src/fmu/dataio/_workflows/case/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ class WfExportCaseMetadata(ert.ErtScript):
356356
This is used for the ERT workflow context. It is prefixed 'Wf' to avoid a
357357
potential naming collisions in fmu-dataio."""
358358

359+
# Ensure ERT execution stops if the workflow fails
360+
stop_on_fail = True
361+
359362
def run(
360363
self,
361364
workflow_args: list[str],

tests/test_ert_integration/test_wf_create_case_metadata.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
UniformParameter,
3333
)
3434
from fmu.settings import get_fmu_directory
35-
from pytest import CaptureFixture, MonkeyPatch
35+
from pytest import MonkeyPatch
3636

3737
from fmu.dataio._interfaces import SumoUploaderInterface
3838
from fmu.dataio._workflows.case._observations import get_ert_observations_table
@@ -228,12 +228,10 @@ def test_create_case_metadata_warns_without_overwriting(
228228

229229

230230
def test_create_case_metadata_caseroot_not_defined(
231-
fmu_snakeoil_project: Path,
232-
monkeypatch: MonkeyPatch,
233-
capsys: CaptureFixture[str],
231+
fmu_snakeoil_project: Path, monkeypatch: MonkeyPatch
234232
) -> None:
235-
"""Test that a proper error message is given if the case path is
236-
input as an undefined ERT variable"""
233+
"""Test that a ERT is stopped and that a proper error message is given
234+
if the case path is input as an undefined ERT variable"""
237235
pathlib.Path(
238236
fmu_snakeoil_project / "ert/bin/workflows/xhook_create_case_metadata"
239237
).write_text(
@@ -247,21 +245,21 @@ def test_create_case_metadata_caseroot_not_defined(
247245

248246
add_create_case_workflow(ert_config_path)
249247

250-
with patch("sys.argv", ["ert", "test_run", "snakeoil.ert", "--disable-monitoring"]):
248+
with (
249+
patch("sys.argv", ["ert", "test_run", "snakeoil.ert", "--disable-monitoring"]),
250+
pytest.raises(SystemExit, match="Ert variable for case path is not defined"),
251+
):
251252
ert.__main__.main()
252253

253-
_stdout, stderr = capsys.readouterr()
254-
assert "ValueError: Ert variable for case path is not defined" in stderr
255-
256254

257255
def test_create_case_metadata_deprecated_arguments_warn(
258256
fmu_snakeoil_project: Path, monkeypatch: MonkeyPatch
259257
) -> None:
260-
"""Now deprecated arguments issue warnings."""
258+
"""Test that deprecated arguments issue warnings."""
261259
pathlib.Path(
262260
fmu_snakeoil_project / "ert/bin/workflows/xhook_create_case_metadata"
263261
).write_text(
264-
"WF_CREATE_CASE_METADATA <CASEPATH_NOT_DEFINED> <CONFIG_PATH> <CASE_DIR>",
262+
"WF_CREATE_CASE_METADATA <SCRATCH>/<USER>/<CASE_DIR> <CONFIG_PATH> <CASE_DIR>",
265263
encoding="utf-8",
266264
)
267265

@@ -322,7 +320,6 @@ def test_create_case_metadata_sumo_env_dev_input_fails(
322320
fmu_snakeoil_project: Path,
323321
monkeypatch: MonkeyPatch,
324322
mock_sumo_uploader: dict[str, MagicMock | AsyncMock],
325-
capsys: CaptureFixture[str],
326323
) -> None:
327324
"""Test that if the sumo_env argument is input as dev it raises an error"""
328325
with open(
@@ -341,13 +338,10 @@ def test_create_case_metadata_sumo_env_dev_input_fails(
341338
with (
342339
patch("sys.argv", ["ert", "test_run", "snakeoil.ert", "--disable-monitoring"]),
343340
pytest.warns(FutureWarning, match="'--sumo_env' is deprecated"),
341+
pytest.raises(SystemExit, match=" Setting sumo environment through argument"),
344342
):
345343
ert.__main__.main()
346344

347-
_stdout, stderr = capsys.readouterr()
348-
assert "ValueError: Setting sumo environment through argument" in stderr
349-
assert "SUMO_ENV" in stderr
350-
351345

352346
@pytest.mark.skipif(
353347
not importlib.util.find_spec("fmu.sumo.uploader"),

0 commit comments

Comments
 (0)