From cb2056c0783e6172e2c5218f6f6a5e8c12e861a1 Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Mon, 11 Mar 2024 09:07:29 +0100 Subject: [PATCH] bug[next]: Mark cupy tests as requires gpu (#1483) It noticed we execute some tests that use cupy in the cpu CSCS-CI. These tests are always executed when cupy is installed (which usually means we have a gpu, but not necessarily). This PR changes this such that they are marked with `requires_gpu` and as such can be disabled. --- .../embedded_tests/test_nd_array_field.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/next_tests/unit_tests/embedded_tests/test_nd_array_field.py b/tests/next_tests/unit_tests/embedded_tests/test_nd_array_field.py index 78a64d9277..3ec630c949 100644 --- a/tests/next_tests/unit_tests/embedded_tests/test_nd_array_field.py +++ b/tests/next_tests/unit_tests/embedded_tests/test_nd_array_field.py @@ -34,7 +34,15 @@ KDim = Dimension("KDim") -@pytest.fixture(params=nd_array_field._nd_array_implementations) +def nd_array_implementation_params(): + for xp in nd_array_field._nd_array_implementations: + if hasattr(nd_array_field, "cp") and xp == nd_array_field.cp: + yield pytest.param(xp, id=xp.__name__, marks=pytest.mark.requires_gpu) + else: + yield pytest.param(xp, id=xp.__name__) + + +@pytest.fixture(params=nd_array_implementation_params()) def nd_array_implementation(request): yield request.param @@ -272,12 +280,16 @@ def test_binary_operations_with_intersection(binary_arithmetic_op, dims, expecte assert np.allclose(op_result.ndarray, expected_result) -@pytest.fixture( - params=itertools.product( - nd_array_field._nd_array_implementations, nd_array_field._nd_array_implementations - ), - ids=lambda param: f"{param[0].__name__}-{param[1].__name__}", -) +def product_nd_array_implementation_params(): + for xp1 in nd_array_field._nd_array_implementations: + for xp2 in nd_array_field._nd_array_implementations: + marks = () + if any(hasattr(nd_array_field, "cp") and xp == nd_array_field.cp for xp in (xp1, xp2)): + marks = pytest.mark.requires_gpu + yield pytest.param((xp1, xp2), id=f"{xp1.__name__}-{xp2.__name__}", marks=marks) + + +@pytest.fixture(params=product_nd_array_implementation_params()) def product_nd_array_implementation(request): yield request.param