Skip to content

Commit 60cdf10

Browse files
Merge 74577ad into 5b93be6
2 parents 5b93be6 + 74577ad commit 60cdf10

File tree

4 files changed

+211
-193
lines changed

4 files changed

+211
-193
lines changed

lib/iris/tests/integration/netcdf/test_delayed_save.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
Integration tests for delayed saving.
77
"""
8+
import re
89
import warnings
910

1011
from cf_units import Unit
@@ -197,19 +198,36 @@ def test_scheduler_types(
197198

198199
if not save_is_delayed:
199200
assert result is None
200-
assert len(logged_warnings) == 2
201201
issued_warnings = [log.message for log in logged_warnings]
202202
else:
203203
assert result is not None
204204
assert len(logged_warnings) == 0
205-
warnings.simplefilter("error")
206-
issued_warnings = result.compute()
205+
with warnings.catch_warnings(record=True) as logged_warnings:
206+
# The compute *returns* warnings from the delayed operations.
207+
issued_warnings = result.compute()
208+
issued_warnings = [
209+
log.message for log in logged_warnings
210+
] + issued_warnings
211+
212+
warning_messages = [warning.args[0] for warning in issued_warnings]
213+
if scheduler_type == "DistributedScheduler":
214+
# Ignore any "large data transfer" messages generated,
215+
# specifically when testing with the Distributed scheduler.
216+
# These may not always occur and don't reflect something we want to
217+
# test for.
218+
large_transfer_message_regex = re.compile(
219+
"Sending large graph.* may cause some slowdown", re.DOTALL
220+
)
221+
warning_messages = [
222+
message
223+
for message in warning_messages
224+
if not large_transfer_message_regex.search(message)
225+
]
207226

208-
assert len(issued_warnings) == 2
227+
# In all cases, should get 2 fill value warnings overall.
228+
assert len(warning_messages) == 2
209229
expected_msg = "contains unmasked data points equal to the fill-value"
210-
assert all(
211-
expected_msg in warning.args[0] for warning in issued_warnings
212-
)
230+
assert all(expected_msg in message for message in warning_messages)
213231

214232
def test_time_of_writing(
215233
self, save_is_delayed, output_path, scheduler_type

0 commit comments

Comments
 (0)