@@ -182,7 +182,7 @@ def visit_Call(self, node: ast.Call) -> ast.Call:
182182
183183def generate_hypothesis_tests (
184184 test_cfg : TestConfig , args : Namespace , function_to_optimize : FunctionToOptimize , function_to_optimize_ast : ast .AST
185- ) -> tuple [dict [str , list [FunctionCalledInTest ]], str ]:
185+ ) -> tuple [dict [str , list [FunctionCalledInTest ]], str , Path | None ]:
186186 """Generate property-based tests using Hypothesis ghostwriter.
187187
188188 This function:
@@ -193,12 +193,14 @@ def generate_hypothesis_tests(
193193 5. Formats the tests with the project formatter
194194
195195 Returns:
196- Tuple of (function_to_tests_map, test_suite_code)
196+ Tuple of (function_to_tests_map, test_suite_code, hypothesis_test_suite_dir)
197+ The hypothesis_test_suite_dir is None if no tests were generated.
197198
198199 """
199200 start_time = time .perf_counter ()
200201 function_to_hypothesis_tests : dict [str , list [FunctionCalledInTest ]] = {}
201202 hypothesis_test_suite_code : str = ""
203+ hypothesis_test_suite_dir : Path | None = None
202204
203205 if (
204206 test_cfg .project_root_path
@@ -212,8 +214,6 @@ def generate_hypothesis_tests(
212214 qualified_function_path = get_qualified_function_path (
213215 function_to_optimize .file_path , args .project_root , function_to_optimize .qualified_name
214216 )
215- logger .info (f"command: hypothesis write { qualified_function_path } " )
216-
217217 hypothesis_result = subprocess .run (
218218 ["hypothesis" , "write" , qualified_function_path ],
219219 capture_output = True ,
@@ -226,11 +226,11 @@ def generate_hypothesis_tests(
226226 logger .debug ("Hypothesis test generation timed out" )
227227 end_time = time .perf_counter ()
228228 logger .debug (f"Hypothesis test generation completed in { end_time - start_time :.2f} seconds" )
229- return function_to_hypothesis_tests , hypothesis_test_suite_code
229+ return function_to_hypothesis_tests , hypothesis_test_suite_code , hypothesis_test_suite_dir
230230
231231 if hypothesis_result .returncode == 0 :
232232 hypothesis_test_suite_code = hypothesis_result .stdout
233- hypothesis_test_suite_dir = Path (tempfile .mkdtemp (dir = test_cfg .tests_root ))
233+ hypothesis_test_suite_dir = Path (tempfile .mkdtemp (prefix = "codeflash_hypothesis_" , dir = test_cfg .tests_root ))
234234 hypothesis_path = hypothesis_test_suite_dir / "test_hypothesis.py"
235235 hypothesis_path .write_text (hypothesis_test_suite_code , encoding = "utf8" )
236236
@@ -250,12 +250,11 @@ def generate_hypothesis_tests(
250250
251251 unparsed = filter_hypothesis_tests_by_function_name (original_code , function_to_optimize .function_name )
252252
253- console .print (f"modified src: { unparsed } " )
254-
255253 hypothesis_test_suite_code = format_code (
256254 args .formatter_cmds ,
257255 hypothesis_path ,
258256 optimized_code = make_hypothesis_tests_deterministic (remove_functions_with_only_any_type (unparsed )),
257+ print_status = False ,
259258 )
260259 with hypothesis_path .open ("w" , encoding = "utf-8" ) as f :
261260 f .write (hypothesis_test_suite_code )
@@ -269,7 +268,7 @@ def generate_hypothesis_tests(
269268 console .rule ()
270269 end_time = time .perf_counter ()
271270 logger .debug (f"Generated hypothesis tests in { end_time - start_time :.2f} seconds" )
272- return function_to_hypothesis_tests , hypothesis_test_suite_code
271+ return function_to_hypothesis_tests , hypothesis_test_suite_code , hypothesis_test_suite_dir
273272
274273 logger .debug (
275274 f"Error running hypothesis write { ': ' + hypothesis_result .stderr if hypothesis_result .stderr else '.' } "
@@ -278,4 +277,4 @@ def generate_hypothesis_tests(
278277
279278 end_time = time .perf_counter ()
280279 logger .debug (f"Hypothesis test generation completed in { end_time - start_time :.2f} seconds" )
281- return function_to_hypothesis_tests , hypothesis_test_suite_code
280+ return function_to_hypothesis_tests , hypothesis_test_suite_code , hypothesis_test_suite_dir
0 commit comments