1616# Test that experimental imports still work
1717def 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
3735def 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
8578def test_experimental_submodule_access ():
@@ -100,14 +93,20 @@ def test_experimental_submodule_access():
10093
10194
10295def 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