Skip to content

Commit

Permalink
use fixtures to manage skips
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Sep 18, 2024
1 parent b67da9d commit 0c37f7d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
26 changes: 26 additions & 0 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

@pytest.fixture
def cuda_device():
from nanoarrow.device import resolve, DeviceType
try:
return resolve(DeviceType.CUDA, 0)
except ValueError:
return None
17 changes: 5 additions & 12 deletions python/tests/test_c_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,8 @@ def test_c_array_duration():
]


def test_device_array_errors():
from nanoarrow.device import DeviceType, resolve

try:
cuda_device = resolve(DeviceType.CUDA, 0)
except ValueError:
def test_device_array_errors(cuda_device):
if not cuda_device:
pytest.skip("CUDA device not available")

# Check that we can't create a CUDA array from CPU buffers
Expand All @@ -652,14 +648,11 @@ def test_device_array_errors():
)


def test_array_from_dlpack_cuda():
from nanoarrow.device import CDeviceArray, DeviceType, resolve
def test_array_from_dlpack_cuda(cuda_device):
from nanoarrow.device import CDeviceArray, DeviceType

cp = pytest.importorskip("cupy")

try:
cuda_device = resolve(DeviceType.CUDA, 0)
except ValueError:
if not cuda_device:
pytest.skip("CUDA device not available")

gpu_validity = cp.array([255], cp.uint8)
Expand Down
9 changes: 3 additions & 6 deletions python/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ def test_c_device_array():
assert array.buffers == darray.array.buffers


def test_c_device_array_from_dlpack():
from nanoarrow.device import DeviceType, resolve
def test_c_device_array_from_dlpack(cuda_device):
from nanoarrow.device import DeviceType

cp = pytest.importorskip("cupy")

try:
cuda_device = resolve(DeviceType.CUDA, 0)
except ValueError:
if not cuda_device:
pytest.skip("CUDA device not available")

assert cuda_device.device_type == DeviceType.CUDA
Expand Down
9 changes: 2 additions & 7 deletions python/tests/test_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,9 @@ def test_dlpack_not_supported():
view.__dlpack_device__()


def test_dlpack_cuda():
from nanoarrow.device import DeviceType, resolve

def test_dlpack_cuda(cuda_device):
cp = pytest.importorskip("cupy")

try:
cuda_device = resolve(DeviceType.CUDA, 0)
except ValueError:
if not cuda_device:
pytest.skip("CUDA device not available")

gpu_array = cp.array([1, 2, 3])
Expand Down

0 comments on commit 0c37f7d

Please sign in to comment.