From 06eb83fcdb8138c191aeef8ea70e5ac771117d5b Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Wed, 8 Jan 2025 10:28:43 +0100 Subject: [PATCH 1/5] Test pre/post-exp hooks w/o monkeypatch --- tests/ert/ui_tests/cli/test_cli.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ert/ui_tests/cli/test_cli.py b/tests/ert/ui_tests/cli/test_cli.py index 9284349b97f..0be48017835 100644 --- a/tests/ert/ui_tests/cli/test_cli.py +++ b/tests/ert/ui_tests/cli/test_cli.py @@ -521,9 +521,7 @@ def test_that_stop_on_fail_workflow_jobs_stop_ert( @pytest.mark.usefixtures("copy_poly_case") -def test_that_pre_post_experiment_hook_works(monkeypatch, capsys): - monkeypatch.setattr(_ert.threading, "_can_raise", False) - +def test_that_pre_post_experiment_hook_works(capsys): # The executable with open("hello_post_exp.sh", "w", encoding="utf-8") as f: f.write( From 5214fa9ac1a7e6749c1320b8c0bc44a0375f2651 Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Wed, 8 Jan 2025 10:30:15 +0100 Subject: [PATCH 2/5] Fixup bad variable naming in test --- tests/ert/ui_tests/cli/test_cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ert/ui_tests/cli/test_cli.py b/tests/ert/ui_tests/cli/test_cli.py index 0be48017835..cd98b6ff466 100644 --- a/tests/ert/ui_tests/cli/test_cli.py +++ b/tests/ert/ui_tests/cli/test_cli.py @@ -540,7 +540,7 @@ def test_that_pre_post_experiment_hook_works(capsys): # The workflow with open("SAY_HELLO_POST_EXP.wf", "w", encoding="utf-8") as s: - s.write("""dump_final_ensemble_id""") + s.write("""alias_for_hello_post_exp_wfjob""") # The executable with open("hello_pre_exp.sh", "w", encoding="utf-8") as f: @@ -560,7 +560,7 @@ def test_that_pre_post_experiment_hook_works(capsys): # The workflow with open("SAY_HELLO_PRE_EXP.wf", "w", encoding="utf-8") as s: - s.write("""dump_first_ensemble_id""") + s.write("""alias_for_hello_pre_exp_wfjob""") with open("poly.ert", mode="a", encoding="utf-8") as fh: fh.write( @@ -568,11 +568,11 @@ def test_that_pre_post_experiment_hook_works(capsys): """ NUM_REALIZATIONS 2 - LOAD_WORKFLOW_JOB SAY_HELLO_POST_EXP dump_final_ensemble_id + LOAD_WORKFLOW_JOB SAY_HELLO_POST_EXP alias_for_hello_post_exp_wfjob LOAD_WORKFLOW SAY_HELLO_POST_EXP.wf POST_EXPERIMENT_DUMP HOOK_WORKFLOW POST_EXPERIMENT_DUMP POST_EXPERIMENT - LOAD_WORKFLOW_JOB SAY_HELLO_PRE_EXP dump_first_ensemble_id + LOAD_WORKFLOW_JOB SAY_HELLO_PRE_EXP alias_for_hello_pre_exp_wfjob LOAD_WORKFLOW SAY_HELLO_PRE_EXP.wf PRE_EXPERIMENT_DUMP HOOK_WORKFLOW PRE_EXPERIMENT_DUMP PRE_EXPERIMENT """ From a911c85a6472bce92571766979e1586d1977528d Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Wed, 8 Jan 2025 11:50:24 +0100 Subject: [PATCH 3/5] Debuggingss --- .github/workflows/test_ert.yml | 11 +++++++++- src/ert/analysis/_es_update.py | 3 +++ src/ert/run_models/base_run_model.py | 5 +++++ tests/ert/ui_tests/cli/test_cli.py | 32 ++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_ert.yml b/.github/workflows/test_ert.yml index e9685cc8f5d..f8c79a963e9 100644 --- a/.github/workflows/test_ert.yml +++ b/.github/workflows/test_ert.yml @@ -54,7 +54,16 @@ jobs: - name: CLI Test if: inputs.test-type == 'cli-tests' run: | - pytest --cov=ert --cov=everest --cov=_ert --cov-report=xml:cov1.xml --junit-xml=junit.xml -o junit_family=legacy -v --benchmark-disable --dist loadgroup tests/ert/ui_tests/cli --durations=25 + echo {{github.workspace}} + pytest -x --cov=ert --cov=everest --cov=_ert --cov-report=xml:cov1.xml --junit-xml=junit.xml -o junit_family=legacy -v --benchmark-disable --dist loadgroup tests/ert/ui_tests/cli --durations=25 + + - name: Upload checkme folder if exists + if: ${{ !cancelled() }} + continue-on-error: true + uses: actions/upload-artifact@v4 + with: + name: folder-artifact + path: '/tmp/pytest-of-runner/**/checkme' - name: Unit Test if: inputs.test-type == 'unit-tests' diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 44a10ea63e8..205116ebab1 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -3,6 +3,7 @@ import functools import logging import time +import traceback from collections.abc import Callable, Iterable, Sequence from fnmatch import fnmatch from typing import ( @@ -876,6 +877,8 @@ def iterative_smoother_update( initial_mask=initial_mask, ) except Exception as e: + print("Exception!") + traceback.print_tb(e.__traceback__) progress_callback( AnalysisErrorEvent( error_msg=str(e), diff --git a/src/ert/run_models/base_run_model.py b/src/ert/run_models/base_run_model.py index d8c795e10ac..79a2c92d76c 100644 --- a/src/ert/run_models/base_run_model.py +++ b/src/ert/run_models/base_run_model.py @@ -7,6 +7,7 @@ import os import shutil import time +import traceback import uuid from abc import ABC, abstractmethod from collections import defaultdict @@ -233,6 +234,10 @@ def group(cls) -> str | None: return None def send_event(self, event: StatusEvents) -> None: + if hasattr(event, "error_msg"): + traceback.print_stack() + print(event.error_msg) + self._status_queue.put(event) def send_smoother_event( diff --git a/tests/ert/ui_tests/cli/test_cli.py b/tests/ert/ui_tests/cli/test_cli.py index cd98b6ff466..44a1e8acafc 100644 --- a/tests/ert/ui_tests/cli/test_cli.py +++ b/tests/ert/ui_tests/cli/test_cli.py @@ -3,8 +3,10 @@ import json import logging import os +import shutil import stat import threading +import traceback from datetime import datetime from pathlib import Path from textwrap import dedent @@ -521,7 +523,7 @@ def test_that_stop_on_fail_workflow_jobs_stop_ert( @pytest.mark.usefixtures("copy_poly_case") -def test_that_pre_post_experiment_hook_works(capsys): +def test_that_pre_post_experiment_hook_works(): # The executable with open("hello_post_exp.sh", "w", encoding="utf-8") as f: f.write( @@ -578,13 +580,31 @@ def test_that_pre_post_experiment_hook_works(capsys): """ ) ) + cwd = os.getcwd() + # Copy cwd one level up - for mode in [ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE]: - run_cli(mode, "--disable-monitor", "poly.ert") + dst = str(Path(cwd) / ".." / "checkme") + print(f"If fail, will copy project w/ fail from {cwd} to {dst}") - captured = capsys.readouterr() - assert "first" in captured.out - assert "just sending regards" in captured.out + for mode in [ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE]: + try: + run_cli(mode, "--disable-monitor", "poly.ert") + except Exception as e: + print(f"{mode}") + print(traceback.format_exc()) + print("\n".join(traceback.format_tb(e.__traceback__))) + print(str(e.__traceback__)) + cwd = os.getcwd() + # Copy cwd one level up + + dst = str(Path(cwd) / ".." / "checkme") + shutil.copytree(cwd, dst) + print(f"Copied project w/ fail from {cwd} to {dst}") + raise AssertionError() from e + + # captured = capsys.readouterr() + # assert "first" in captured.out + # assert "just sending regards" in captured.out @pytest.fixture(name="mock_cli_run") From 85a5b8628407dff5f8c899effa398495ff38233c Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Tue, 14 Jan 2025 11:46:49 +0100 Subject: [PATCH 4/5] Try parametrize instead of for loop --- tests/ert/ui_tests/cli/test_cli.py | 39 +++++++++--------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/tests/ert/ui_tests/cli/test_cli.py b/tests/ert/ui_tests/cli/test_cli.py index 44a1e8acafc..9fb4c6e5f00 100644 --- a/tests/ert/ui_tests/cli/test_cli.py +++ b/tests/ert/ui_tests/cli/test_cli.py @@ -3,10 +3,8 @@ import json import logging import os -import shutil import stat import threading -import traceback from datetime import datetime from pathlib import Path from textwrap import dedent @@ -523,7 +521,11 @@ def test_that_stop_on_fail_workflow_jobs_stop_ert( @pytest.mark.usefixtures("copy_poly_case") -def test_that_pre_post_experiment_hook_works(): +@pytest.mark.parametrize( + "mode", + [ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE], +) +def test_that_pre_post_experiment_hook_works(capsys, mode): # The executable with open("hello_post_exp.sh", "w", encoding="utf-8") as f: f.write( @@ -580,31 +582,12 @@ def test_that_pre_post_experiment_hook_works(): """ ) ) - cwd = os.getcwd() - # Copy cwd one level up - - dst = str(Path(cwd) / ".." / "checkme") - print(f"If fail, will copy project w/ fail from {cwd} to {dst}") - - for mode in [ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE]: - try: - run_cli(mode, "--disable-monitor", "poly.ert") - except Exception as e: - print(f"{mode}") - print(traceback.format_exc()) - print("\n".join(traceback.format_tb(e.__traceback__))) - print(str(e.__traceback__)) - cwd = os.getcwd() - # Copy cwd one level up - - dst = str(Path(cwd) / ".." / "checkme") - shutil.copytree(cwd, dst) - print(f"Copied project w/ fail from {cwd} to {dst}") - raise AssertionError() from e - - # captured = capsys.readouterr() - # assert "first" in captured.out - # assert "just sending regards" in captured.out + + run_cli(mode, "--disable-monitor", "poly.ert") + + captured = capsys.readouterr() + assert "first" in captured.out + assert "just sending regards" in captured.out @pytest.fixture(name="mock_cli_run") From c600b9b0a8e727844573857699d1eec5cf3d777c Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Thu, 16 Jan 2025 08:49:10 +0100 Subject: [PATCH 5/5] Try --disable-monitoring instead of --disable-monitor --- tests/ert/ui_tests/cli/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ert/ui_tests/cli/test_cli.py b/tests/ert/ui_tests/cli/test_cli.py index 9fb4c6e5f00..7259e971733 100644 --- a/tests/ert/ui_tests/cli/test_cli.py +++ b/tests/ert/ui_tests/cli/test_cli.py @@ -583,7 +583,7 @@ def test_that_pre_post_experiment_hook_works(capsys, mode): ) ) - run_cli(mode, "--disable-monitor", "poly.ert") + run_cli(mode, "--disable-monitoring", "poly.ert") captured = capsys.readouterr() assert "first" in captured.out