Skip to content

Commit f080dfd

Browse files
committed
Catch warnings more explicitly in tests
Should any other warnings be raised within the units being tested the tests will start failing. This will catch the right warnings more explicitly.
1 parent d451553 commit f080dfd

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

tests/ert/unit_tests/config/test_rft_config.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from io import BytesIO
55
from pathlib import Path
66
from typing import Any, cast
7+
from warnings import WarningMessage
78

89
import numpy as np
910
import polars as pl
@@ -1526,19 +1527,22 @@ def test_that_wildcard_well_with_wildcard_time_without_any_response_is_warned_ab
15261527
assert any(all(e_w in str(w) for e_w in expected_warnings) for w in warnings)
15271528

15281529

1529-
def _collect_rft_response_warnings(
1530-
well: str, time: str
1531-
) -> list[warnings.WarningMessage]:
1530+
def _collect_rft_response_warnings(well: str, time: str) -> list[WarningMessage]:
15321531
rft_config = RFTConfig(
15331532
input_files=["BASE.RFT"],
15341533
data_to_read={
15351534
well: {time: ["PRESSURE", "SWAT"]},
15361535
},
15371536
)
1538-
with warnings.catch_warnings(record=True) as w:
1537+
with warnings.catch_warnings(record=True) as ws:
15391538
rft_config.read_from_file("/tmp/does_not_exist", 1, 1)
15401539

1541-
return w
1540+
return [
1541+
w
1542+
for w in ws
1543+
if issubclass(w.category, PostExperimentWarning)
1544+
and "Could not find response" in str(w.message)
1545+
]
15421546

15431547

15441548
def test_that_wildcard_well_with_wildcard_time_with_any_response_is_not_warned_about(

tests/ert/unit_tests/config/test_summary_config.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from pathlib import Path
66
from textwrap import dedent
7+
from warnings import WarningMessage
78

89
import hypothesis.strategies as st
910
import polars as pl
@@ -274,13 +275,18 @@ def mock_read_summary(*args):
274275

275276
def _collect_summary_response_warnings(
276277
response_key: str, simulated_response_key: str
277-
) -> list[warnings.WarningMessage]:
278+
) -> list[WarningMessage]:
278279
summary_config = SummaryConfig(keys=[response_key])
279-
with warnings.catch_warnings(record=True) as w:
280+
with warnings.catch_warnings(record=True) as ws:
280281
summary_config._warn_about_missing_summary_responses(
281282
response_keys=[simulated_response_key], filename="foo"
282283
)
283-
return w
284+
return [
285+
w
286+
for w in ws
287+
if issubclass(w.category, PostExperimentWarning)
288+
and "Could not find response" in str(w.message)
289+
]
284290

285291

286292
def test_that_key_with_wildcard_with_response_is_not_warned_about():

0 commit comments

Comments
 (0)