diff --git a/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py b/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py index 57a3c2f3725..f54a6ec1d89 100644 --- a/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py +++ b/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py @@ -16,7 +16,7 @@ from resdata.summary import Summary -def await_process_tee(process, *out_files): +def await_process_tee(process, *out_files) -> int: """Wait for process to finish, "tee"-ing the subprocess' stdout into all the given file objects. @@ -316,7 +316,7 @@ def _get_log_name(self, eclrun_config=None): logname_extension = "LOG" return f"{self.base_name}.{logname_extension}" - def execEclipse(self, eclrun_config=None): + def execEclipse(self, eclrun_config=None) -> int: use_eclrun = eclrun_config is not None log_name = self._get_log_name(eclrun_config=eclrun_config) @@ -358,7 +358,12 @@ def runEclipse(self, eclrun_config=None, retries_left=2, backoff_sleep=None): f.write("ECLIPSE simulation complete - NOT checked for errors.") else: if return_code != 0: - raise subprocess.CalledProcessError(return_code, self.sim.executable) + command = ( + self._get_run_command(eclrun_config) + if self.sim is None + else self._get_legacy_run_command() + ) + raise subprocess.CalledProcessError(return_code, command) try: self.assertECLEND() diff --git a/tests/unit_tests/shared/share/test_ecl_run.py b/tests/unit_tests/shared/share/test_ecl_run.py index d2917658a40..b10a55add43 100644 --- a/tests/unit_tests/shared/share/test_ecl_run.py +++ b/tests/unit_tests/shared/share/test_ecl_run.py @@ -408,6 +408,15 @@ def test_run_nonzero_exit_code(init_ecl100_config, source_root): erun.runEclipse() +@pytest.mark.requires_eclipse +def test_non_existing_eclipse_version(init_ecl100_config, source_root): + Path("FOO.DATA").write_text("", encoding="utf-8") + econfig = ecl_config.Ecl100Config() + + with pytest.raises(KeyError, match="2079.3"): + econfig.sim("2079.3") + + @pytest.mark.requires_eclipse def test_run_api(init_ecl100_config, source_root): shutil.copy( diff --git a/tests/unit_tests/shared/share/test_ecl_run_new_config.py b/tests/unit_tests/shared/share/test_ecl_run_new_config.py index a1370b8c637..b04333dd30d 100644 --- a/tests/unit_tests/shared/share/test_ecl_run_new_config.py +++ b/tests/unit_tests/shared/share/test_ecl_run_new_config.py @@ -4,6 +4,8 @@ import re import shutil import stat +import subprocess +from pathlib import Path from unittest import mock import pytest @@ -178,6 +180,20 @@ def test_failed_run(source_root): erun.runEclipse(eclrun_config=eclrun_config) +@pytest.mark.requires_eclipse +@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config") +def test_failed_run_nonzero_returncode(monkeypatch): + Path("FOO.DATA").write_text("") + econfig = ecl_config.Ecl100Config() + eclrun_config = ecl_config.EclrunConfig(econfig, "2021.3") + erun = ecl_run.EclRun("FOO.DATA", None) + monkeypatch.setattr("ecl_run.EclRun.execEclipse", mock.MagicMock(return_value=1)) + with pytest.raises( + subprocess.CalledProcessError, match="Command .*eclrun.* non-zero exit status 1" + ): + erun.runEclipse(eclrun_config=eclrun_config) + + @pytest.mark.requires_eclipse @pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config") def test_failed_run_OK(source_root):