22import pathlib
33import tomlkit
44
5+ from codeflash .code_utils .code_utils import add_addopts_to_pyproject
56from end_to_end_test_utilities import CoverageExpectation , TestConfig , run_codeflash_command , run_with_retries
67
78
89def run_test (expected_improvement_pct : int ) -> bool :
9- try :
10- # Modify Pyproject file
11- with pathlib .Path .open (
12- (pathlib .Path (__file__ ).parent .parent .parent / "pyproject.toml" ).resolve (), encoding = "utf-8"
13- ) as f :
14- original_content = f .read ()
15- data = tomlkit .parse (original_content )
16- data ["tool" ]["pytest" ] = {}
17- data ["tool" ]["pytest" ]["ini_options" ] = {}
18- data ["tool" ]["pytest" ]["ini_options" ]["addopts" ] = ["-n=auto" , "-n" , "1" , "-n 1" , "-n 1" , "-n auto" ]
19- with pathlib .Path .open (
20- (pathlib .Path (__file__ ).parent .parent .parent / "pyproject.toml" ).resolve (), "w" , encoding = "utf-8"
21- ) as f :
22- f .write (tomlkit .dumps (data ))
10+ with add_addopts_to_pyproject ():
2311 config = TestConfig (
2412 file_path = "topological_sort.py" ,
2513 function_name = "Graph.topologicalSort" ,
@@ -35,9 +23,6 @@ def run_test(expected_improvement_pct: int) -> bool:
3523 )
3624 cwd = (pathlib .Path (__file__ ).parent .parent .parent / "code_to_optimize" ).resolve ()
3725 return_var = run_codeflash_command (cwd , config , expected_improvement_pct )
38- finally :
39- with pathlib .Path .open (pathlib .Path ("pyproject.toml" ), "w" , encoding = "utf-8" ) as f :
40- f .write (original_content )
4126 return return_var
4227
4328
0 commit comments