From 7294ac8bd0f7beef3cdfaad2a26051489542ecda Mon Sep 17 00:00:00 2001 From: Ruth Comer <10599679+rcomer@users.noreply.github.com> Date: Sat, 2 Dec 2023 12:18:47 +0000 Subject: [PATCH] move some skips to function level --- lib/cartopy/tests/mpl/test_caching.py | 8 ++++---- lib/cartopy/tests/mpl/test_features.py | 13 +++++++------ lib/cartopy/tests/test_img_transform.py | 8 ++++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/cartopy/tests/mpl/test_caching.py b/lib/cartopy/tests/mpl/test_caching.py index c23e548e6..688dfda0a 100644 --- a/lib/cartopy/tests/mpl/test_caching.py +++ b/lib/cartopy/tests/mpl/test_caching.py @@ -20,10 +20,9 @@ from cartopy.tests.conftest import _HAS_PYKDTREE_OR_SCIPY -if not _HAS_PYKDTREE_OR_SCIPY: - pytest.skip('pykdtree or scipy is required', allow_module_level=True) +if _HAS_PYKDTREE_OR_SCIPY: + from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE, WMTSRasterSource -from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE, WMTSRasterSource import cartopy.io.shapereader from cartopy.mpl import _MPL_38 from cartopy.mpl.feature_artist import FeatureArtist @@ -155,7 +154,8 @@ def test_contourf_transform_path_counting(): @pytest.mark.filterwarnings("ignore:TileMatrixLimits") @pytest.mark.network -@pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.') +@pytest.mark.skipif(not _HAS_PYKDTREE_OR_SCIPY or not _OWSLIB_AVAILABLE, + reason='OWSLib and at least one of pykdtree or scipy is required') def test_wmts_tile_caching(): image_cache = WMTSRasterSource._shared_image_cache image_cache.clear() diff --git a/lib/cartopy/tests/mpl/test_features.py b/lib/cartopy/tests/mpl/test_features.py index d5e90727d..960a9c021 100644 --- a/lib/cartopy/tests/mpl/test_features.py +++ b/lib/cartopy/tests/mpl/test_features.py @@ -13,10 +13,8 @@ from cartopy.tests.conftest import _HAS_PYKDTREE_OR_SCIPY -if not _HAS_PYKDTREE_OR_SCIPY: - pytest.skip('pykdtree or scipy is required', allow_module_level=True) - -from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE +if _HAS_PYKDTREE_OR_SCIPY: + from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE @pytest.mark.filterwarnings("ignore:Downloading") @@ -49,6 +47,7 @@ def test_natural_earth_custom(): return ax.figure +@pytest.mark.skipif(not _HAS_PYKDTREE_OR_SCIPY, reason='pykdtree or scipy is required') @pytest.mark.mpl_image_compare(filename='gshhs_coastlines.png', tolerance=0.95) def test_gshhs(): ax = plt.axes(projection=ccrs.Mollweide()) @@ -64,7 +63,8 @@ def test_gshhs(): @pytest.mark.network -@pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.') +@pytest.mark.skipif(not _HAS_PYKDTREE_OR_SCIPY or not _OWSLIB_AVAILABLE, + reason='OWSLib and at least one of pykdtree or scipy is required') @pytest.mark.xfail(raises=ParseError, reason="Bad XML returned from the URL") @pytest.mark.mpl_image_compare(filename='wfs.png') @@ -79,7 +79,8 @@ def test_wfs(): @pytest.mark.network -@pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.') +@pytest.mark.skipif(not _HAS_PYKDTREE_OR_SCIPY or not _OWSLIB_AVAILABLE, + reason='OWSLib and at least one of pykdtree or scipy is required') @pytest.mark.xfail(raises=ParseError, reason="Bad XML returned from the URL") @pytest.mark.mpl_image_compare(filename='wfs_france.png') diff --git a/lib/cartopy/tests/test_img_transform.py b/lib/cartopy/tests/test_img_transform.py index 7b1be111a..c26a1f7af 100644 --- a/lib/cartopy/tests/test_img_transform.py +++ b/lib/cartopy/tests/test_img_transform.py @@ -8,8 +8,12 @@ from numpy.testing import assert_array_equal import pytest -from cartopy.tests.conftest import (_HAS_PYKDTREE, _HAS_SCIPY, requires_pykdtree, - requires_scipy) +from cartopy.tests.conftest import ( + _HAS_PYKDTREE, + _HAS_SCIPY, + requires_pykdtree, + requires_scipy, +) if not (_HAS_PYKDTREE or _HAS_SCIPY):