Skip to content

Commit 2bfd402

Browse files
committed
TST: Define new test skip in conftest instead of copy-paste
1 parent 2632bbc commit 2bfd402

File tree

6 files changed

+30
-47
lines changed

6 files changed

+30
-47
lines changed

cuda_bindings/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
import pytest
4+
5+
skipif_compute_sanitizer_is_running = pytest.mark.skipif(
6+
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
7+
reason="The compute-sanitizer is running, and this test causes an API error.",
8+
)

cuda_bindings/tests/test_cuda.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8-
import os
98
import platform
109
import shutil
1110
import textwrap
1211

1312
import numpy as np
1413
import pytest
14+
from conftest import skipif_compute_sanitizer_is_running
1515

1616
import cuda.cuda as cuda
1717
import cuda.cudart as cudart
@@ -84,10 +84,7 @@ def test_cuda_memcpy():
8484
assert err == cuda.CUresult.CUDA_SUCCESS
8585

8686

87-
@pytest.mark.skipif(
88-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
89-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
90-
)
87+
@skipif_compute_sanitizer_is_running
9188
def test_cuda_array():
9289
(err,) = cuda.cuInit(0)
9390
assert err == cuda.CUresult.CUDA_SUCCESS
@@ -241,10 +238,7 @@ def test_cuda_uuid_list_access():
241238
assert err == cuda.CUresult.CUDA_SUCCESS
242239

243240

244-
@pytest.mark.skipif(
245-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
246-
reason="FIXME: This test causes an API error.",
247-
)
241+
@skipif_compute_sanitizer_is_running
248242
def test_cuda_cuModuleLoadDataEx():
249243
(err,) = cuda.cuInit(0)
250244
assert err == cuda.CUresult.CUDA_SUCCESS
@@ -632,10 +626,7 @@ def test_cuda_coredump_attr():
632626
assert err == cuda.CUresult.CUDA_SUCCESS
633627

634628

635-
@pytest.mark.skipif(
636-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
637-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
638-
)
629+
@skipif_compute_sanitizer_is_running
639630
def test_get_error_name_and_string():
640631
(err,) = cuda.cuInit(0)
641632
assert err == cuda.CUresult.CUDA_SUCCESS
@@ -964,10 +955,7 @@ def test_CUmemDecompressParams_st():
964955
assert int(desc.dstActBytes) == 0
965956

966957

967-
@pytest.mark.skipif(
968-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
969-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
970-
)
958+
@skipif_compute_sanitizer_is_running
971959
def test_all_CUresult_codes():
972960
max_code = int(max(cuda.CUresult))
973961
# Smoke test. CUDA_ERROR_UNKNOWN = 999, but intentionally using literal value.
@@ -1000,30 +988,21 @@ def test_all_CUresult_codes():
1000988
assert num_good >= 76 # CTK 11.0.3_450.51.06
1001989

1002990

1003-
@pytest.mark.skipif(
1004-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
1005-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
1006-
)
991+
@skipif_compute_sanitizer_is_running
1007992
def test_cuKernelGetName_failure():
1008993
err, name = cuda.cuKernelGetName(0)
1009994
assert err == cuda.CUresult.CUDA_ERROR_INVALID_VALUE
1010995
assert name is None
1011996

1012997

1013-
@pytest.mark.skipif(
1014-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
1015-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
1016-
)
998+
@skipif_compute_sanitizer_is_running
1017999
def test_cuFuncGetName_failure():
10181000
err, name = cuda.cuFuncGetName(0)
10191001
assert err == cuda.CUresult.CUDA_ERROR_INVALID_VALUE
10201002
assert name is None
10211003

10221004

1023-
@pytest.mark.skipif(
1024-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
1025-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
1026-
)
1005+
@skipif_compute_sanitizer_is_running
10271006
@pytest.mark.skipif(
10281007
driverVersionLessThan(12080) or not supportsCudaAPI("cuCheckpointProcessGetState"),
10291008
reason="When API was introduced",

cuda_bindings/tests/test_cudart.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# is strictly prohibited.
88
import ctypes
99
import math
10-
import os
1110

1211
import numpy as np
1312
import pytest
13+
from conftest import skipif_compute_sanitizer_is_running
1414

1515
import cuda.cuda as cuda
1616
import cuda.cudart as cudart
@@ -71,10 +71,7 @@ def test_cudart_memcpy():
7171
assertSuccess(err)
7272

7373

74-
@pytest.mark.skipif(
75-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
76-
reason="The compute-sanitizer is running, and this test intentionally causes an API error.",
77-
)
74+
@skipif_compute_sanitizer_is_running
7875
def test_cudart_hostRegister():
7976
# Use hostRegister API to check for correct enum return values
8077
page_size = 80

cuda_core/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ def clean_up_cffi_files():
6464
os.remove(f)
6565
except FileNotFoundError:
6666
pass # noqa: SIM105
67+
68+
69+
skipif_compute_sanitizer_is_running = pytest.mark.skipif(
70+
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
71+
reason="The compute-sanitizer is running, and this test causes an API error.",
72+
)

cuda_core/tests/test_cuda_utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4-
import os
54

65
import pytest
6+
from conftest import skipif_compute_sanitizer_is_running
77

88
from cuda.bindings import driver, runtime
99
from cuda.core.experimental._utils import cuda_utils
@@ -41,13 +41,8 @@ def test_runtime_cuda_error_explanations_health():
4141
assert not extra_expl
4242

4343

44-
@pytest.mark.skipif(
45-
os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
46-
reason=(
47-
"The compute-sanitizer is running, and this test causes an API error "
48-
"when the driver is too old to know about all of the error codes."
49-
),
50-
)
44+
# this test causes an API error when the driver is too old to know about all of the error codes
45+
@skipif_compute_sanitizer_is_running
5146
def test_check_driver_error():
5247
num_unexpected = 0
5348
for error in driver.CUresult:

cuda_core/tests/test_linker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4-
import os
54

65
import pytest
6+
from conftest import skipif_compute_sanitizer_is_running
77

88
from cuda.core.experimental import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker
99
from cuda.core.experimental._module import ObjectCode
@@ -141,10 +141,8 @@ def test_linker_link_invalid_target_type(compile_ptx_functions):
141141
linker.link("invalid_target")
142142

143143

144-
@pytest.mark.skipif(
145-
is_culink_backend and os.environ.get("CUDA_PYTHON_SANITIZER_RUNNING", "0") == "1",
146-
reason="The compute-sanitizer is running, and this test causes an API error using the culink API.",
147-
)
144+
# this test causes an API error when using the culink API
145+
@skipif_compute_sanitizer_is_running
148146
def test_linker_get_error_log(compile_ptx_functions):
149147
options = LinkerOptions(arch=ARCH)
150148

0 commit comments

Comments
 (0)