Skip to content

Commit 4b43d21

Browse files
committed
Reorganize all the tests
1 parent 8c9a103 commit 4b43d21

45 files changed

Lines changed: 188 additions & 276 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cuda_bindings/cuda/bindings/_test_helpers/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

cuda_bindings/cuda/bindings/_test_helpers/arch_check.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

cuda_bindings/tests/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@
1212

1313
import cuda.bindings.driver as cuda
1414

15-
# Ensure cuda_python_test_helpers is importable. Prefer an installed package;
16-
# fall back to the sibling checkout. Keep in sync with cuda_core/tests/conftest.py.
15+
# Keep in sync with cuda_core/tests/conftest.py.
1716
try:
18-
import cuda_python_test_helpers # noqa: F401
17+
import cuda_python_test_helpers._pytest_plugin # noqa: F401
1918
except ImportError as e:
2019
# Don't call .resolve(): resolving symlinks can make parents[2] point
2120
# somewhere other than the monorepo root if a sub-directory is symlinked.
2221
_test_helpers_root = pathlib.Path(__file__).parents[2] / "cuda_python_test_helpers"
2322
if not _test_helpers_root.is_dir():
2423
raise RuntimeError(f"cuda-python-test-helpers not installed and not found at {_test_helpers_root}") from e
24+
for _k in list(sys.modules):
25+
if _k == "cuda_python_test_helpers" or _k.startswith("cuda_python_test_helpers."):
26+
del sys.modules[_k]
2527
sys.path.insert(0, str(_test_helpers_root))
2628
importlib.invalidate_caches()
2729

30+
pytest_plugins = ["cuda_python_test_helpers._pytest_plugin"]
31+
2832

2933
def pytest_configure(config):
3034
# When using `parallel-threads` set up mini-plugin to ensure each thread has a CUDA context

cuda_bindings/tests/nvml/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44

55
import pytest
6-
7-
from cuda.bindings._test_helpers.arch_check import hardware_supports_nvml
6+
from cuda_python_test_helpers.arch_check import hardware_supports_nvml
87

98
if not hardware_supports_nvml():
109
pytest.skip("NVML not supported on this platform", allow_module_level=True)

cuda_bindings/tests/nvml/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from collections import namedtuple
55

66
import pytest
7+
from cuda_python_test_helpers.arch_check import unsupported_before # noqa: F401
78

89
from cuda.bindings import nvml
9-
from cuda.bindings._test_helpers.arch_check import unsupported_before # noqa: F401
1010

1111

1212
class NVMLInitializer:

cuda_bindings/tests/nvml/test_pynvml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import pytest
1010

1111
from cuda.bindings import nvml
12+
from cuda_python_test_helpers import IS_WINDOWS, IS_WSL
1213

13-
from . import util
1414
from .conftest import unsupported_before
1515

1616
XFAIL_LEGACY_NVLINK_MSG = "Legacy NVLink test expected to fail."
@@ -64,7 +64,7 @@ def test_device_get_handle_by_pci_bus_id(ngpus, pci_info):
6464

6565

6666
@pytest.mark.parametrize("scope", [nvml.AffinityScope.NODE, nvml.AffinityScope.SOCKET])
67-
@pytest.mark.skipif(util.is_wsl() or util.is_windows(), reason="Not supported on WSL or Windows")
67+
@pytest.mark.skipif(IS_WSL or IS_WINDOWS, reason="Not supported on WSL or Windows")
6868
def test_device_get_memory_affinity(handles, scope):
6969
size = 1024
7070
for handle in handles:
@@ -75,7 +75,7 @@ def test_device_get_memory_affinity(handles, scope):
7575

7676

7777
@pytest.mark.parametrize("scope", [nvml.AffinityScope.NODE, nvml.AffinityScope.SOCKET])
78-
@pytest.mark.skipif(util.is_wsl() or util.is_windows(), reason="Not supported on WSL or Windows")
78+
@pytest.mark.skipif(IS_WSL or IS_WINDOWS, reason="Not supported on WSL or Windows")
7979
def test_device_get_cpu_affinity_within_scope(handles, scope):
8080
size = 1024
8181
for handle in handles:

cuda_bindings/tests/nvml/util.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
import functools
6-
import platform
7-
from pathlib import Path
8-
95
from cuda.bindings import nvml
106

11-
current_os = platform.system()
12-
if current_os == "VMkernel":
13-
current_os = "Linux" # Treat VMkernel as Linux
14-
15-
16-
def is_windows(os=current_os):
17-
return os == "Windows"
18-
19-
20-
def is_linux(os=current_os):
21-
return os == "Linux"
22-
23-
24-
@functools.cache
25-
def is_wsl(os=current_os):
26-
return os == "Linux" and "microsoft" in Path("/proc/version").read_text().lower()
27-
287

298
def is_vgpu(device):
309
"""

cuda_bindings/tests/test_cuda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
import numpy as np
1212
import pytest
13+
from cuda_python_test_helpers.mempool import xfail_if_mempool_oom
1314

1415
import cuda.bindings.driver as cuda
1516
import cuda.bindings.runtime as cudart
1617
from cuda.bindings import driver
17-
from cuda.bindings._test_helpers.mempool import xfail_if_mempool_oom
1818

1919

2020
def driverVersionLessThan(target):

cuda_bindings/tests/test_cudart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import numpy as np
88
import pytest
9+
from cuda_python_test_helpers.mempool import xfail_if_mempool_oom
910

1011
import cuda.bindings.driver as cuda
1112
import cuda.bindings.runtime as cudart
1213
from cuda import pathfinder
1314
from cuda.bindings import runtime
14-
from cuda.bindings._test_helpers.mempool import xfail_if_mempool_oom
1515

1616

1717
def isSuccess(err):

cuda_bindings/tests/test_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import sys
88

99
import pytest
10-
11-
from cuda.bindings._test_helpers.pep723 import has_package_requirements_or_skip
10+
from cuda_python_test_helpers.pep723 import has_package_requirements_or_skip
1211

1312
examples_path = os.path.join(os.path.dirname(__file__), "..", "examples")
1413
examples_files = glob.glob(os.path.join(examples_path, "**/*.py"), recursive=True)

0 commit comments

Comments
 (0)