Skip to content

Commit 4f34fdd

Browse files
committed
Address review comments: use pytest.deprecated_call and clarify warning behavior
- Replace manual warning catching with pytest.deprecated_call() for cleaner tests - Add documentation clarifying that deprecation warnings are only emitted at module import time, not on each attribute access - Update test_experimental_utils_module docstring to explain warning behavior
1 parent a040505 commit 4f34fdd

2 files changed

Lines changed: 37 additions & 31 deletions

File tree

cuda_core/cuda/core/experimental/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@
4848

4949

5050
def _warn_deprecated():
51-
"""Emit a deprecation warning for using the experimental namespace."""
51+
"""Emit a deprecation warning for using the experimental namespace.
52+
53+
Note: This warning is only when the experimental module is first imported.
54+
Subsequent accesses to attributes (like utils, Device, etc.) do not trigger
55+
additional warnings since they are already set in the module namespace.
56+
Only accessing submodules via __getattr__ (e.g., _device, _utils) will trigger
57+
additional warnings.
58+
"""
5259
warnings.warn(
5360
"The cuda.core.experimental namespace is deprecated. "
5461
"Please import directly from cuda.core instead. "

cuda_core/tests/test_experimental_backward_compat.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@
1616
# Test that experimental imports still work
1717
def test_experimental_imports_work():
1818
"""Test that imports from experimental namespace still work."""
19-
with warnings.catch_warnings(record=True) as w:
20-
warnings.simplefilter("always")
21-
22-
# Test main module import
19+
# Clear cached module to ensure warning is emitted
20+
import sys
21+
if 'cuda.core.experimental' in sys.modules:
22+
del sys.modules['cuda.core.experimental']
23+
24+
# Test main module import - should emit deprecation warning
25+
with pytest.deprecated_call():
2326
import cuda.core.experimental
24-
25-
# Should emit deprecation warning
26-
assert len(w) >= 1
27-
assert issubclass(w[0].category, DeprecationWarning)
28-
assert "deprecated" in str(w[0].message).lower()
29-
30-
# Test that symbols are accessible
31-
assert hasattr(cuda.core.experimental, "Device")
32-
assert hasattr(cuda.core.experimental, "Stream")
33-
assert hasattr(cuda.core.experimental, "Buffer")
34-
assert hasattr(cuda.core.experimental, "system")
27+
28+
# Test that symbols are accessible
29+
assert hasattr(cuda.core.experimental, "Device")
30+
assert hasattr(cuda.core.experimental, "Stream")
31+
assert hasattr(cuda.core.experimental, "Buffer")
32+
assert hasattr(cuda.core.experimental, "system")
3533

3634

3735
def test_experimental_symbols_are_same_objects():
@@ -63,23 +61,18 @@ def test_experimental_direct_imports():
6361
if 'cuda.core.experimental' in sys.modules:
6462
del sys.modules['cuda.core.experimental']
6563

66-
with warnings.catch_warnings(record=True) as w:
67-
warnings.simplefilter("always")
68-
69-
# Test various import patterns
64+
# Test various import patterns - warning is emitted once at module import time
65+
with pytest.deprecated_call():
7066
from cuda.core.experimental import Device, Stream, Buffer
7167
from cuda.core.experimental import Program, Kernel, ObjectCode
7268
from cuda.core.experimental import Graph, GraphBuilder, Event
7369
from cuda.core.experimental import Linker, launch
7470
from cuda.core.experimental import system
75-
76-
# Should have warnings (at least one from the initial import)
77-
assert len(w) >= 1, f"Expected at least 1 deprecation warning, got {len(w)}"
78-
79-
# Verify objects are usable
80-
assert Device is not None
81-
assert Stream is not None
82-
assert Buffer is not None
71+
72+
# Verify objects are usable
73+
assert Device is not None
74+
assert Stream is not None
75+
assert Buffer is not None
8376

8477

8578
def test_experimental_submodule_access():
@@ -100,14 +93,20 @@ def test_experimental_submodule_access():
10093

10194

10295
def test_experimental_utils_module():
103-
"""Test that experimental.utils module works."""
96+
"""Test that experimental.utils module works.
97+
98+
Note: The deprecation warning is only emitted once at import time when
99+
cuda.core.experimental is first imported. Accessing utils or importing
100+
from utils does not trigger additional warnings since utils is already
101+
set as an attribute in the module namespace.
102+
"""
104103
import cuda.core.experimental
105104

106-
# Should be able to access utils
105+
# Should be able to access utils (no warning on access, only on initial import)
107106
assert hasattr(cuda.core.experimental, "utils")
108107
assert cuda.core.experimental.utils is not None
109108

110-
# Should have expected utilities
109+
# Should have expected utilities (no warning on import from utils submodule)
111110
from cuda.core.experimental.utils import StridedMemoryView, args_viewable_as_strided_memory
112111
assert StridedMemoryView is not None
113112
assert args_viewable_as_strided_memory is not None

0 commit comments

Comments
 (0)