diff --git a/tests/conftest.py b/tests/conftest.py index 8d3a4f3f..39904ae2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ """Pytest fixtures.""" from collections.abc import Callable +from contextlib import suppress from functools import wraps from types import ModuleType from typing import ParamSpec, TypeVar, cast @@ -36,7 +37,9 @@ def library(request: pytest.FixtureRequest) -> Backend: # numpydoc ignore=PR01, msg = "argument of skip_xp_backend must be a Backend enum" raise TypeError(msg) if skip_library == elem: - reason = cast(str, marker.kwargs.get("reason", "skip_xp_backend")) + reason = skip_library.value + with suppress(KeyError): + reason += ":" + cast(str, marker.kwargs["reason"]) pytest.skip(reason=reason) return elem diff --git a/tests/test_at.py b/tests/test_at.py index 49abe0e4..4bd09c6a 100644 --- a/tests/test_at.py +++ b/tests/test_at.py @@ -31,7 +31,7 @@ def assert_copy(array: Array, copy: bool | None) -> Generator[None, None, None]: @pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:read-only backend without .at support" + Backend.SPARSE, reason="read-only backend without .at support" ) @pytest.mark.parametrize( ("kwargs", "expect_copy"), diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 692d486b..4847cb9f 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -26,7 +26,7 @@ # mypy: disable-error-code=no-untyped-usage -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims") class TestAtLeastND: def test_0D(self, xp: ModuleType): x = xp.asarray(1.0) @@ -98,7 +98,7 @@ def test_xp(self, xp: ModuleType): xp_assert_equal(y, x) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype") class TestCov: def test_basic(self, xp: ModuleType): xp_assert_close( @@ -137,9 +137,7 @@ def test_device(self, xp: ModuleType, device: Device): x = xp.asarray([1, 2, 3], device=device) assert get_device(cov(x)) == device - @pytest.mark.skip_xp_backend( - Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp" - ) + @pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp") def test_xp(self, xp: ModuleType): xp_assert_close( cov(xp.asarray([[0.0, 2.0], [1.0, 1.0], [2.0, 0.0]]).T, xp=xp), @@ -147,7 +145,7 @@ def test_xp(self, xp: ModuleType): ) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device") class TestCreateDiagonal: def test_1d(self, xp: ModuleType): # from np.diag tests @@ -193,10 +191,10 @@ def test_xp(self, xp: ModuleType): xp_assert_equal(y, xp.asarray([[1, 0], [0, 2]])) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims") class TestExpandDims: - @pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:tuple index out of range") - @pytest.mark.skip_xp_backend(Backend.TORCH, reason="torch:tuple index out of range") + @pytest.mark.skip_xp_backend(Backend.DASK, reason="tuple index out of range") + @pytest.mark.skip_xp_backend(Backend.TORCH, reason="tuple index out of range") def test_functionality(self, xp: ModuleType): def _squeeze_all(b: Array) -> Array: """Mimics `np.squeeze(b)`. `xpx.squeeze`?""" @@ -254,7 +252,7 @@ def test_xp(self, xp: ModuleType): assert y.shape == (1, 1, 1, 3) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims") class TestKron: def test_basic(self, xp: ModuleType): # Using 0-dimensional array @@ -351,9 +349,7 @@ def test_xp(self, xp: ModuleType): xp_assert_equal(nunique(a, xp=xp), xp.asarray(3)) -@pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray" -) +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no arange, no device") class TestPad: def test_simple(self, xp: ModuleType): a = xp.arange(1, 4) @@ -403,8 +399,8 @@ def test_list_of_tuples_width(self, xp: ModuleType): assert padded.shape == (4, 4) -@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort") -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray") +@pytest.mark.skip_xp_backend(Backend.DASK, reason="no argsort") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device kwarg in asarray") class TestSetDiff1D: @pytest.mark.skip_xp_backend( Backend.TORCH, reason="index_select not implemented for uint32" @@ -440,9 +436,7 @@ def test_device(self, xp: ModuleType, device: Device): x2 = xp.asarray([2, 3, 4], device=device) assert get_device(setdiff1d(x1, x2)) == device - @pytest.mark.skip_xp_backend( - Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp" - ) + @pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp") def test_xp(self, xp: ModuleType): x1 = xp.asarray([3, 8, 20]) x2 = xp.asarray([2, 3, 4]) @@ -451,7 +445,7 @@ def test_xp(self, xp: ModuleType): xp_assert_equal(actual, expected) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype") class TestSinc: def test_simple(self, xp: ModuleType): xp_assert_equal(sinc(xp.asarray(0.0)), xp.asarray(1.0)) diff --git a/tests/test_testing.py b/tests/test_testing.py index 41fc6673..dc315663 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -17,9 +17,7 @@ xp_assert_equal, pytest.param( xp_assert_close, - marks=pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:no isdtype" - ), + marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"), ), ], ) @@ -40,19 +38,15 @@ def test_assert_close_equal_basic(xp: ModuleType, func: Callable[..., None]): # func(xp.asarray([1, 2]), xp.asarray([1, 3]), err_msg="hello") -@pytest.mark.skip_xp_backend(Backend.NUMPY, reason="numpy:test other ns vs. numpy") -@pytest.mark.skip_xp_backend( - Backend.NUMPY_READONLY, reason="numpy_readonly:test other ns vs. numpy" -) +@pytest.mark.skip_xp_backend(Backend.NUMPY, reason="test other ns vs. numpy") +@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="test other ns vs. numpy") @pytest.mark.parametrize( "func", [ xp_assert_equal, pytest.param( xp_assert_close, - marks=pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:no isdtype" - ), + marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"), ), ], ) @@ -65,7 +59,7 @@ def test_assert_close_equal_namespace(xp: ModuleType, func: Callable[..., None]) func(xp.asarray([0]), [0]) -@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype") +@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype") def test_assert_close_tolerance(xp: ModuleType): xp_assert_close(xp.asarray([100.0]), xp.asarray([102.0]), rtol=0.03) with pytest.raises(AssertionError): diff --git a/tests/test_utils.py b/tests/test_utils.py index f053f177..fff3f0f2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,9 +12,9 @@ class TestIn1D: - @pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort") + @pytest.mark.skip_xp_backend(Backend.DASK, reason="no argsort") @pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:no unique_inverse, no device kwarg in asarray" + Backend.SPARSE, reason="no unique_inverse, no device kwarg in asarray" ) # cover both code paths @pytest.mark.parametrize("n", [9, 15]) @@ -25,19 +25,15 @@ def test_no_invert_assume_unique(self, xp: ModuleType, n: int): actual = in1d(x1, x2) xp_assert_equal(actual, expected) - @pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse: no device kwarg in asarray" - ) + @pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device kwarg in asarray") def test_device(self, xp: ModuleType, device: Device): x1 = xp.asarray([3, 8, 20], device=device) x2 = xp.asarray([2, 3, 4], device=device) assert get_device(in1d(x1, x2)) == device + @pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY, reason="explicit xp") @pytest.mark.skip_xp_backend( - Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp" - ) - @pytest.mark.skip_xp_backend( - Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray" + Backend.SPARSE, reason="no arange, no device kwarg in asarray" ) def test_xp(self, xp: ModuleType): x1 = xp.asarray([1, 6])