Skip to content

Commit 9c13237

Browse files
committed
add _cuda_headers_available() guard to conftest files
Add a helper that skips tests when no CUDA path is set, but asserts that the include/ subdirectory exists when one is — surfacing stale or incomplete toolkit roots at collection time instead of letting them fail later in compilation. Applied in both the root conftest.py and cuda_core/tests/conftest.py. Made-with: Cursor
1 parent 0255083 commit 9c13237

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

conftest.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5+
import os
6+
57
import pytest
68

79
from cuda.pathfinder import get_cuda_path_or_home
810

911

12+
# Please keep in sync with the copy in cuda_core/tests/conftest.py.
13+
def _cuda_headers_available() -> bool:
14+
"""Return True if CUDA headers are available, False if no CUDA path is set.
15+
16+
Raises AssertionError if a CUDA path is set but has no include/ subdirectory.
17+
"""
18+
cuda_path = get_cuda_path_or_home()
19+
if cuda_path is None:
20+
return False
21+
assert os.path.isdir(os.path.join(cuda_path, "include")), (
22+
f"CUDA path {cuda_path} does not contain an 'include' subdirectory"
23+
)
24+
return True
25+
26+
1027
def pytest_collection_modifyitems(config, items): # noqa: ARG001
11-
cuda_home = get_cuda_path_or_home()
28+
have_headers = _cuda_headers_available()
1229
for item in items:
1330
nodeid = item.nodeid.replace("\\", "/")
1431

@@ -32,6 +49,10 @@ def pytest_collection_modifyitems(config, items): # noqa: ARG001
3249
):
3350
item.add_marker(pytest.mark.cython)
3451

35-
# Gate core cython tests on CUDA_HOME
36-
if "core" in item.keywords and not cuda_home:
37-
item.add_marker(pytest.mark.skip(reason="CUDA_HOME not set; skipping core cython tests"))
52+
# Gate core cython tests on CUDA_PATH
53+
if "core" in item.keywords and not have_headers:
54+
item.add_marker(
55+
pytest.mark.skip(
56+
reason="Environment variable CUDA_PATH or CUDA_HOME is not set: skipping core cython tests"
57+
)
58+
)

cuda_core/tests/conftest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,22 @@ def test_something(memory_resource_factory):
254254
return request.param
255255

256256

257+
# Please keep in sync with the copy in the top-level conftest.py.
258+
def _cuda_headers_available() -> bool:
259+
"""Return True if CUDA headers are available, False if no CUDA path is set.
260+
261+
Raises AssertionError if a CUDA path is set but has no include/ subdirectory.
262+
"""
263+
cuda_path = get_cuda_path_or_home()
264+
if cuda_path is None:
265+
return False
266+
assert os.path.isdir(os.path.join(cuda_path, "include")), (
267+
f"CUDA path {cuda_path} does not contain an 'include' subdirectory"
268+
)
269+
return True
270+
271+
257272
skipif_need_cuda_headers = pytest.mark.skipif(
258-
get_cuda_path_or_home() is None,
273+
not _cuda_headers_available(),
259274
reason="need CUDA header",
260275
)

0 commit comments

Comments
 (0)