From c2fd265018656e9a19c3e48e076c74816c954eaf Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 10 Sep 2020 17:46:47 -0700 Subject: [PATCH 1/3] Use `pytest.importorskip` for C-extension tests As these bits may or may not be built depending on whether C-extensions are supported, have pytest skip them if they are not `import`able. --- numcodecs/tests/test_blosc.py | 3 +++ numcodecs/tests/test_lz4.py | 4 ++++ numcodecs/tests/test_zstd.py | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/numcodecs/tests/test_blosc.py b/numcodecs/tests/test_blosc.py index edc14faf..c41b2f1a 100644 --- a/numcodecs/tests/test_blosc.py +++ b/numcodecs/tests/test_blosc.py @@ -6,6 +6,9 @@ import pytest +pytest.importorskip("numcodecs.blosc") + + from numcodecs import blosc from numcodecs.blosc import Blosc from numcodecs.tests.common import (check_encode_decode, diff --git a/numcodecs/tests/test_lz4.py b/numcodecs/tests/test_lz4.py index 94a01821..f14d44fb 100644 --- a/numcodecs/tests/test_lz4.py +++ b/numcodecs/tests/test_lz4.py @@ -2,6 +2,10 @@ import numpy as np +import pytest + + +pytest.importorskip("numcodecs.lz4") from numcodecs.lz4 import LZ4 diff --git a/numcodecs/tests/test_zstd.py b/numcodecs/tests/test_zstd.py index de291c12..31bb7090 100644 --- a/numcodecs/tests/test_zstd.py +++ b/numcodecs/tests/test_zstd.py @@ -2,6 +2,10 @@ import numpy as np +import pytest + + +pytest.importorskip("numcodecs.zstd") from numcodecs.zstd import Zstd From dd6a341562314297b3ba82da34d89cd33b7fba89 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 11 Sep 2020 12:40:45 -0700 Subject: [PATCH 2/3] Make linter happier --- numcodecs/tests/test_blosc.py | 10 +++++++--- numcodecs/tests/test_lz4.py | 8 ++++++-- numcodecs/tests/test_zstd.py | 8 ++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/numcodecs/tests/test_blosc.py b/numcodecs/tests/test_blosc.py index c41b2f1a..b9616bae 100644 --- a/numcodecs/tests/test_blosc.py +++ b/numcodecs/tests/test_blosc.py @@ -6,11 +6,15 @@ import pytest -pytest.importorskip("numcodecs.blosc") +try: + from numcodecs import blosc + from numcodecs.blosc import Blosc +except ImportError: + pytest.skip( + "numcodecs.blosc not available", allow_module_level=True + ) -from numcodecs import blosc -from numcodecs.blosc import Blosc from numcodecs.tests.common import (check_encode_decode, check_encode_decode_partial, check_config, diff --git a/numcodecs/tests/test_lz4.py b/numcodecs/tests/test_lz4.py index f14d44fb..33a274eb 100644 --- a/numcodecs/tests/test_lz4.py +++ b/numcodecs/tests/test_lz4.py @@ -5,10 +5,14 @@ import pytest -pytest.importorskip("numcodecs.lz4") +try: + from numcodecs.lz4 import LZ4 +except ImportError: + pytest.skip( + "numcodecs.lz4 not available", allow_module_level=True + ) -from numcodecs.lz4 import LZ4 from numcodecs.tests.common import (check_encode_decode, check_config, check_repr, check_backwards_compatibility, check_err_decode_object_buffer, diff --git a/numcodecs/tests/test_zstd.py b/numcodecs/tests/test_zstd.py index 31bb7090..98348b87 100644 --- a/numcodecs/tests/test_zstd.py +++ b/numcodecs/tests/test_zstd.py @@ -5,10 +5,14 @@ import pytest -pytest.importorskip("numcodecs.zstd") +try: + from numcodecs.zstd import Zstd +except ImportError: + pytest.skip( + "numcodecs.zstd not available", allow_module_level=True + ) -from numcodecs.zstd import Zstd from numcodecs.tests.common import (check_encode_decode, check_config, check_repr, check_backwards_compatibility, check_err_decode_object_buffer, From fa978cb31bc52de56ad8a0bfc033141c7f283848 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 11 Sep 2020 14:02:59 -0700 Subject: [PATCH 3/3] Mark pytest skip fallback as no cover --- numcodecs/tests/test_blosc.py | 2 +- numcodecs/tests/test_lz4.py | 2 +- numcodecs/tests/test_zstd.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/numcodecs/tests/test_blosc.py b/numcodecs/tests/test_blosc.py index b9616bae..168d5f2f 100644 --- a/numcodecs/tests/test_blosc.py +++ b/numcodecs/tests/test_blosc.py @@ -9,7 +9,7 @@ try: from numcodecs import blosc from numcodecs.blosc import Blosc -except ImportError: +except ImportError: # pragma: no cover pytest.skip( "numcodecs.blosc not available", allow_module_level=True ) diff --git a/numcodecs/tests/test_lz4.py b/numcodecs/tests/test_lz4.py index 33a274eb..a7cfadd0 100644 --- a/numcodecs/tests/test_lz4.py +++ b/numcodecs/tests/test_lz4.py @@ -7,7 +7,7 @@ try: from numcodecs.lz4 import LZ4 -except ImportError: +except ImportError: # pragma: no cover pytest.skip( "numcodecs.lz4 not available", allow_module_level=True ) diff --git a/numcodecs/tests/test_zstd.py b/numcodecs/tests/test_zstd.py index 98348b87..ccdf1556 100644 --- a/numcodecs/tests/test_zstd.py +++ b/numcodecs/tests/test_zstd.py @@ -7,7 +7,7 @@ try: from numcodecs.zstd import Zstd -except ImportError: +except ImportError: # pragma: no cover pytest.skip( "numcodecs.zstd not available", allow_module_level=True )