From de94d709116de7ab9a983a8ee7fa47696d291cc1 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 8 Feb 2026 14:14:16 +0800 Subject: [PATCH] Improve test test_dataset_to_strings_with_none_values to avoid internet connection issues --- pygmt/tests/test_datatypes_dataset.py | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pygmt/tests/test_datatypes_dataset.py b/pygmt/tests/test_datatypes_dataset.py index 1c4168a3159..1d217e794a4 100644 --- a/pygmt/tests/test_datatypes_dataset.py +++ b/pygmt/tests/test_datatypes_dataset.py @@ -156,16 +156,25 @@ def test_dataset_to_strings_with_none_values(): See the bug report at https://github.com/GenericMappingTools/pygmt/issues/3170. """ + # Sometimes, the test may fail in CI due to intermittent internet connection issue. + # Catch the FileNotFoundError exception so that we can focus on the bug. tiles = ["@N30E060.earth_age_01m_g.nc", "@N30E090.earth_age_01m_g.nc"] - paths = which(fname=tiles, download="a") - assert len(paths) == 2 - # 'paths' may contain an empty string or not, depending on if the tiles are cached. - if "" not in paths: # Contains two valid paths. - # Delete the cached tiles and try again. - for path in paths: - Path(path).unlink() - with pytest.warns(expected_warning=RuntimeWarning) as record: - paths = which(fname=tiles, download="a") - assert len(record) == 1 + try: + paths = which(fname=tiles, download="a") assert len(paths) == 2 - assert "" in paths + + # 'paths' may contain an empty string or not, depending on if tiles are cached. + if "" not in paths: # Contains two valid paths. + # Delete the cached tiles and try again. + for path in paths: + Path(path).unlink() + with pytest.warns(expected_warning=RuntimeWarning) as record: # noqa: PT031 + try: + paths = which(fname=tiles, download="a") + assert len(record) == 1 + assert len(paths) == 2 + assert "" in paths + except FileNotFoundError: + pass + except FileNotFoundError: + pass