@@ -50,13 +50,6 @@ def _with_print_repro_enabled(self):
5050 else :
5151 os .environ ["HELION_PRINT_REPRO" ] = original
5252
53- def _clear_captures (self ):
54- """Clear pytest capture fixtures if available."""
55- if hasattr (self , "_capfd" ):
56- self ._capfd .readouterr ()
57- if hasattr (self , "_caplog" ):
58- self ._caplog .clear ()
59-
6053 def _create_kernel (self , ** kwargs ):
6154 """Create a simple 1D kernel for testing.
6255
@@ -85,21 +78,19 @@ def test_print_repro_env_var(self):
8578 torch .manual_seed (0 )
8679 x = torch .randn ([128 ], dtype = torch .float32 , device = DEVICE )
8780
88- self ._clear_captures ()
89-
90- result = kernel (x )
91- torch .testing .assert_close (result , x + 1 )
81+ with self .capture_logs () as log_capture :
82+ result = kernel (x )
83+ torch .testing .assert_close (result , x + 1 )
9284
93- # Extract repro script from logs (use records to get the raw message without formatting)
94- assert hasattr (self , "_caplog" ), "caplog fixture not available"
95- repro_script = None
96- for record in self ._caplog .records :
97- if "# === HELION KERNEL REPRO ===" in record .message :
98- repro_script = record .message
99- break
85+ # Extract repro script from logs (use records to get the raw message without formatting)
86+ repro_script = None
87+ for record in log_capture .records :
88+ if "# === HELION KERNEL REPRO ===" in record .message :
89+ repro_script = record .message
90+ break
10091
101- if repro_script is None :
102- self .fail ("No repro script found in logs" )
92+ if repro_script is None :
93+ self .fail ("No repro script found in logs" )
10394
10495 # Normalize range_warp_specializes=[None] to [] for comparison
10596 normalized_script = repro_script .replace (
@@ -149,8 +140,6 @@ def test_print_repro_on_autotune_error(self):
149140 torch .manual_seed (0 )
150141 x = torch .randn ([128 ], dtype = torch .float32 , device = DEVICE )
151142
152- self ._clear_captures ()
153-
154143 # Mock do_bench to fail on the second config with PTXASError (warn level)
155144 from torch ._inductor .runtime .triton_compat import PTXASError
156145 from triton .testing import do_bench as original_do_bench
@@ -163,13 +152,13 @@ def mock_do_bench(*args, **kwargs):
163152 raise PTXASError ("Mocked PTXAS error" )
164153 return original_do_bench (* args , ** kwargs )
165154
166- with mock .patch ("helion.autotuner.base_search.do_bench" , mock_do_bench ):
167- # Autotune will try both configs, second one will fail and print repro
168- kernel .autotune ([x ], force = False )
155+ with self .capture_output () as output_capture :
156+ with mock .patch ("helion.autotuner.base_search.do_bench" , mock_do_bench ):
157+ # Autotune will try both configs, second one will fail and print repro
158+ kernel .autotune ([x ], force = False )
169159
170- # Extract repro script from stderr
171- assert hasattr (self , "_capfd" ), "capfd fixture not available"
172- captured = "" .join (self ._capfd .readouterr ())
160+ # Extract repro script from stderr
161+ captured = "" .join (output_capture .readouterr ())
173162
174163 # Verify that a repro script was printed for the failing config
175164 self .assertIn ("# === HELION KERNEL REPRO ===" , captured )
0 commit comments