Skip to content

Commit 4610d88

Browse files
authored
Add a workaround for internet issues that fails test_dataset_to_strings_with_none_values (#4394)
1 parent c13aa78 commit 4610d88

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

pygmt/tests/test_datatypes_dataset.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,25 @@ def test_dataset_to_strings_with_none_values():
156156
157157
See the bug report at https://github.com/GenericMappingTools/pygmt/issues/3170.
158158
"""
159+
# Sometimes, the test may fail in CI due to intermittent internet connection issue.
160+
# Catch the FileNotFoundError exception so that we can focus on the bug.
159161
tiles = ["@N30E060.earth_age_01m_g.nc", "@N30E090.earth_age_01m_g.nc"]
160-
paths = which(fname=tiles, download="a")
161-
assert len(paths) == 2
162-
# 'paths' may contain an empty string or not, depending on if the tiles are cached.
163-
if "" not in paths: # Contains two valid paths.
164-
# Delete the cached tiles and try again.
165-
for path in paths:
166-
Path(path).unlink()
167-
with pytest.warns(expected_warning=RuntimeWarning) as record:
168-
paths = which(fname=tiles, download="a")
169-
assert len(record) == 1
162+
try:
163+
paths = which(fname=tiles, download="a")
170164
assert len(paths) == 2
171-
assert "" in paths
165+
166+
# 'paths' may contain an empty string or not, depending on if tiles are cached.
167+
if "" not in paths: # Contains two valid paths.
168+
# Delete the cached tiles and try again.
169+
for path in paths:
170+
Path(path).unlink()
171+
with pytest.warns(expected_warning=RuntimeWarning) as record: # noqa: PT031
172+
try:
173+
paths = which(fname=tiles, download="a")
174+
assert len(record) == 1
175+
assert len(paths) == 2
176+
assert "" in paths
177+
except FileNotFoundError:
178+
pass
179+
except FileNotFoundError:
180+
pass

0 commit comments

Comments
 (0)