From ac53170327c365ca6bcba77aa01c64027c2dd501 Mon Sep 17 00:00:00 2001 From: Andy Jost Date: Thu, 22 Jan 2026 08:26:18 -0800 Subject: [PATCH] fix: add init_cuda fixture to tests requiring CUDA context Four tests in test_utils.py relied on CuPy implicitly creating a CUDA context but failed when pytest-randomly ordered them after tests using the init_cuda fixture, which pops the context on cleanup. --- cuda_core/tests/test_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cuda_core/tests/test_utils.py b/cuda_core/tests/test_utils.py index a3c62a6aee..dd9c52e817 100644 --- a/cuda_core/tests/test_utils.py +++ b/cuda_core/tests/test_utils.py @@ -345,7 +345,7 @@ def _get_ptr(array): for view_as in ["dlpack", "cai"] ], ) -def test_view_sliced_external(shape, slices, stride_order, view_as): +def test_view_sliced_external(init_cuda, shape, slices, stride_order, view_as): if view_as == "dlpack": if np is None: pytest.skip("NumPy is not installed") @@ -380,7 +380,7 @@ def test_view_sliced_external(shape, slices, stride_order, view_as): ("stride_order", "view_as"), [(stride_order, view_as) for stride_order in ["C", "F"] for view_as in ["dlpack", "cai"]], ) -def test_view_sliced_external_negative_offset(stride_order, view_as): +def test_view_sliced_external_negative_offset(init_cuda, stride_order, view_as): shape = (5,) if view_as == "dlpack": if np is None: @@ -422,7 +422,7 @@ def test_view_sliced_external_negative_offset(stride_order, view_as): ) @pytest.mark.parametrize("shape", [(0,), (0, 0), (0, 0, 0)]) @pytest.mark.parametrize("dtype", [np.int64, np.uint8, np.float64]) -def test_view_zero_size_array(api, shape, dtype): +def test_view_zero_size_array(init_cuda, api, shape, dtype): cp = pytest.importorskip("cupy") x = cp.empty(shape, dtype=dtype) @@ -446,7 +446,7 @@ def test_from_buffer_with_non_power_of_two_itemsize(): assert view.dtype == dtype -def test_struct_array(): +def test_struct_array(init_cuda): cp = pytest.importorskip("cupy") x = np.array([(1.0, 2), (2.0, 3)], dtype=[("array1", np.float64), ("array2", np.int64)])