From 093c43e6aa119060de21021d8eeb5159d265d02c Mon Sep 17 00:00:00 2001 From: DanSava Date: Thu, 14 Nov 2024 13:32:10 +0200 Subject: [PATCH] Simplify test logic --- .../ert/unit_tests/config/test_ert_config.py | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/tests/ert/unit_tests/config/test_ert_config.py b/tests/ert/unit_tests/config/test_ert_config.py index 93e5af10a2a..5aafff6b9d2 100644 --- a/tests/ert/unit_tests/config/test_ert_config.py +++ b/tests/ert/unit_tests/config/test_ert_config.py @@ -4,6 +4,7 @@ import os import os.path import stat +import warnings from datetime import date from pathlib import Path from textwrap import dedent @@ -1537,9 +1538,7 @@ def test_general_option_in_local_config_has_priority_over_site_config(): @pytest.mark.usefixtures("use_tmpdir") -def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, recwarn): - caplog.set_level(logging.WARNING) - +def test_warning_raised_when_summary_key_and_no_simulation_job_present(): with open("job_file", "w", encoding="utf-8") as fout: fout.write("EXECUTABLE echo\nARGLIST \n") @@ -1548,22 +1547,18 @@ def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, r fout.write("NUM_REALIZATIONS 1\n") fout.write("SUMMARY *\n") fout.write("ECLBASE RESULT_SUMMARY\n") - fout.write("INSTALL_JOB job_name job_file\n") fout.write( "FORWARD_MODEL job_name(=A/, =/x)\n" ) + with warnings.catch_warnings(record=True) as all_warnings: + ErtConfig.from_file("config_file.ert") - ErtConfig.from_file("config_file.ert") - - # Check no warning is logged when config contains - # forward model step with and as arguments - assert not caplog.text - assert len(recwarn) == 1 - assert issubclass(recwarn[0].category, ConfigWarning) - assert ( - recwarn[0].message.info.message + assert any( + str(w.message) == "Config contains a SUMMARY key but no forward model steps known to generate a summary file" + for w in all_warnings + if isinstance(w.message, ConfigWarning) ) @@ -1571,11 +1566,7 @@ def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, r "job_name", ["eclipse", "eclipse100", "flow", "FLOW", "ECLIPSE100"] ) @pytest.mark.usefixtures("use_tmpdir") -def test_no_warning_when_summary_key_and_simulation_job_present( - caplog, recwarn, job_name -): - caplog.set_level(logging.WARNING) - +def test_no_warning_when_summary_key_and_simulation_job_present(job_name): with open("job_file", "w", encoding="utf-8") as fout: fout.write("EXECUTABLE echo\nARGLIST \n") @@ -1589,9 +1580,8 @@ def test_no_warning_when_summary_key_and_simulation_job_present( fout.write( f"FORWARD_MODEL {job_name}(=A/, =/x)\n" ) - - ErtConfig.from_file("config_file.ert") - # Check no warning is logged when config contains # forward model step with and as arguments - assert not any(w.message for w in recwarn if issubclass(w.category, ConfigWarning)) + with warnings.catch_warnings(): + warnings.simplefilter("error", category=ConfigWarning) + ErtConfig.from_file("config_file.ert")