Skip to content

Commit 19e6649

Browse files
authored
Fix #2377: Reorganize the test helpers (where appropriate) to cuda_python_test_helpers (#2384)
* Experiment: Install test_helpers as a package * Try something different in CI * Reorganize all the tests * Update a few more imports
1 parent d9da442 commit 19e6649

48 files changed

Lines changed: 217 additions & 302 deletions

Some content is hidden

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

‎.github/workflows/coverage.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ jobs:
335335
336336
- name: Install test dependencies and coverage tools
337337
run: |
338-
.venv/Scripts/pip install -v ./cuda_python_test_helpers
339338
.venv/Scripts/pip install coverage pytest-cov Cython
340339
.venv/Scripts/pip install --group ./cuda_pathfinder/pyproject.toml:test
341340
.venv/Scripts/pip install --group ./cuda_bindings/pyproject.toml:test

‎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/pixi.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ cuda-version = ["12.*", "13.3.*"]
1515
[feature.test.dependencies]
1616
cuda-bindings = { path = "." }
1717
pytest = ">=6.2.4"
18+
19+
[feature.test.pypi-dependencies]
20+
cuda-python-test-helpers = { path = "../cuda_python_test_helpers", editable = true }
1821
pytest-benchmark = ">=3.4.1"
1922
pytest-randomly = "*"
2023
pytest-repeat = "*"

‎cuda_bindings/tests/conftest.py‎

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

44
import functools
5+
import importlib
56
import inspect
67
import pathlib
78
import sys
89
from contextlib import contextmanager
9-
from importlib.metadata import PackageNotFoundError, distribution
1010

1111
import pytest
1212

1313
import cuda.bindings.driver as cuda
1414

15-
# Import shared test helpers for tests across subprojects.
16-
# PLEASE KEEP IN SYNC with copies in other conftest.py in this repo.
17-
_test_helpers_root = pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers"
15+
# Keep in sync with cuda_core/tests/conftest.py.
1816
try:
19-
distribution("cuda-python-test-helpers")
20-
except PackageNotFoundError as exc:
17+
import cuda_python_test_helpers._pytest_plugin # noqa: F401
18+
except ImportError as e:
19+
# Don't call .resolve(): resolving symlinks can make parents[2] point
20+
# somewhere other than the monorepo root if a sub-directory is symlinked.
21+
_test_helpers_root = pathlib.Path(__file__).parents[2] / "cuda_python_test_helpers"
2122
if not _test_helpers_root.is_dir():
22-
raise RuntimeError(
23-
f"cuda-python-test-helpers not installed; expected checkout path {_test_helpers_root}"
24-
) from exc
25-
26-
test_helpers_root = str(_test_helpers_root)
27-
if test_helpers_root not in sys.path:
28-
sys.path.insert(0, test_helpers_root)
23+
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]
27+
sys.path.insert(0, str(_test_helpers_root))
28+
importlib.invalidate_caches()
29+
30+
pytest_plugins = ["cuda_python_test_helpers._pytest_plugin"]
2931

3032

3133
def pytest_configure(config):

‎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):

0 commit comments

Comments
 (0)