Skip to content

Commit

Permalink
Add warning filters for tests.
Browse files Browse the repository at this point in the history
this should reduce the warning spam so that we can hopefully notice
problematic warnings
  • Loading branch information
JHolba committed Feb 29, 2024
1 parent dff7dba commit c3fa537
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 3 deletions.
28 changes: 28 additions & 0 deletions tests/unit_tests/config/config_dict_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any, List, Literal, Optional, Tuple, Union
from warnings import filterwarnings

import hypothesis.strategies as st
from hypothesis import assume, note
Expand Down Expand Up @@ -530,6 +531,33 @@ def _observation_dates(

@st.composite
def config_generators(draw, use_eclbase=booleans):
filterwarnings(
"ignore",
message=".*Too small observation error in observation.*",
category=UserWarning,
)
filterwarnings(
"ignore",
message=".*MIN_REALIZATIONS set to more than NUM_REALIZATIONS.*",
category=UserWarning,
)
filterwarnings(
"ignore", message=r".*Segment [^\s]* start after stop.*", category=UserWarning
)
filterwarnings(
"ignore",
message=r".*Segment [^\s]* does not contain any time steps.*",
category=UserWarning,
)
filterwarnings(
"ignore", message=".*input contained no data.*", category=UserWarning
)
filterwarnings(
"ignore", message=".*Setting ECLBASE without using.*", category=UserWarning
)
filterwarnings(
"ignore", message=".*overflow encountered in.*", category=RuntimeWarning
)
config_values = draw(ert_config_values(use_eclbase=use_eclbase))

should_exist_files = [job_path for _, job_path in config_values.install_job]
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/config/parsing/test_lark_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def test_that_realisation_is_a_alias_of_realization():
assert config["NUM_REALIZATIONS"] == 1


@pytest.mark.filterwarnings(
"ignore:.*Using DEFINE with substitution strings that are not of the form '<KEY>'.*:ert.config.ConfigWarning"
)
@pytest.mark.usefixtures("use_tmpdir")
def test_that_redefines_are_applied_correctly_as_forward_model_args():
test_config_file_name = "test.ert"
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/config/test_analysis_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def test_analysis_config_from_file_is_same_as_from_dict():
)


@pytest.mark.filterwarnings(
"ignore:.*MIN_REALIZATIONS set to more than NUM_REALIZATIONS.*:ert.config.ConfigWarning"
)
@pytest.mark.parametrize(
"num_realization, min_realizations, expected_min_real",
[
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def test_that_double_comments_are_handled(tmpdir):
assert ert_config.model_config.jobname_format_string == "&SUM$VAR@12@#£¤/<"


@pytest.mark.filterwarnings("ignore:.*Unknown keyword.*:ert.config.ConfigWarning")
def test_bad_user_config_file_error_message(tmp_path):
(tmp_path / "test.ert").write_text("NUM_REL 10\n")
with pytest.raises(ConfigValidationError, match="NUM_REALIZATIONS must be set"):
Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests/config/test_transfer_functions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
from warnings import filterwarnings

import numpy as np
import pytest
from hypothesis import assume, given
from hypothesis import strategies as st
from scipy.stats import norm

from ert.config import TransferFunction


@pytest.fixture(autouse=True)
def filter_warnings():
filterwarnings(
"ignore",
message=".*trans_derff suffered from catastrophic loss of precision.*",
category=UserWarning,
)
filterwarnings(
"ignore", message=".*overflow encountered in.*", category=RuntimeWarning
)


def nice_floats(*args, **kwargs):
return st.floats(*args, allow_nan=False, allow_infinity=False, **kwargs)

Expand Down
8 changes: 7 additions & 1 deletion tests/unit_tests/test_enkf_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from ert.enkf_main import create_run_path, ensemble_context, sample_prior


@pytest.mark.filterwarnings(
"ignore:Setting ECLBASE without using.*:ert.config.ConfigWarning"
)
@pytest.mark.parametrize(
"config_dict",
[
Expand Down Expand Up @@ -44,7 +47,10 @@ def test_create_run_context(prior_ensemble, config_dict):
assert substitutions.get("<ECLBASE>") == "name<IENS>"


def test_create_run_context_separate_base_and_name(monkeypatch, prior_ensemble):
@pytest.mark.filterwarnings(
"ignore:Setting ECLBASE without using.*:ert.config.ConfigWarning"
)
def test_create_run_context_separate_base_and_name(prior_ensemble):
iteration = 0
ensemble_size = 10
config = ErtConfig.from_dict({"JOBNAME": "name<IENS>", "ECLBASE": "base<IENS>"})
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/test_load_forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def test_load_forward_model(snake_oil_default_storage):
] # Check that status is as expected


@pytest.mark.filterwarnings(
"ignore:Setting ECLBASE without using.*:ert.config.ConfigWarning"
)
@pytest.mark.usefixtures("use_tmpdir")
@pytest.mark.parametrize(
"summary_configuration, expected",
Expand Down
18 changes: 16 additions & 2 deletions tests/unit_tests/test_run_path_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from pathlib import Path
from textwrap import dedent
from warnings import filterwarnings

import pytest

Expand All @@ -12,6 +13,13 @@
from ert.storage import StorageAccessor


@pytest.fixture(autouse=True)
def filter_configwarning():
filterwarnings(
"ignore", message="Setting ECLBASE without using.*", category=UserWarning
)


@pytest.mark.usefixtures("use_tmpdir")
def test_that_run_template_replace_symlink_does_not_write_to_source(prior_ensemble):
"""This test is meant to test that we can have a symlinked file in the
Expand Down Expand Up @@ -326,10 +334,13 @@ def test_that_data_file_sets_num_cpu(eclipse_data, expected_cpus):
assert int(ert_config.substitution_list["<NUM_CPU>"]) == expected_cpus


@pytest.mark.filterwarnings(
"ignore:.*RUNPATH keyword contains deprecated value placeholders.*:ert.config.ConfigWarning"
)
@pytest.mark.usefixtures("use_tmpdir")
def test_that_runpath_substitution_remain_valid(prior_ensemble):
def test_that_deprecated_runpath_substitution_remain_valid(prior_ensemble):
"""
This checks that runpath substitution remain intact.
This checks that deprecated runpath substitution, using %d, remain intact.
"""
config_text = dedent(
"""
Expand Down Expand Up @@ -538,6 +549,9 @@ def test_num_cpu_subst(monkeypatch, tmp_path, append, numcpu, storage):
),
],
)
@pytest.mark.filterwarnings(
"ignore:.*RUNPATH keyword contains deprecated value placeholders.*:ert.config.ConfigWarning"
)
@pytest.mark.usefixtures("use_tmpdir")
def test_that_runpaths_are_raised_when_invalid(run_path, expected_raise, msg):
"""
Expand Down

0 comments on commit c3fa537

Please sign in to comment.