Skip to content

Commit bf06c3b

Browse files
committed
shifted cleanup
1 parent c3e1c06 commit bf06c3b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

codeflash/optimization/optimizer.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,18 @@ def run(self) -> None:
166166
function_optimizer = self.create_function_optimizer(
167167
function_to_optimize, function_to_optimize_ast, function_to_tests, validated_original_code[original_module_path].source_code
168168
)
169-
best_optimization = function_optimizer.optimize_function()
170-
self.test_files = TestFiles(test_files=[])
169+
try:
170+
best_optimization = function_optimizer.optimize_function()
171+
finally:
172+
for test_file in function_optimizer.test_files.get_by_type(TestType.GENERATED_REGRESSION).test_files:
173+
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
174+
test_file.benchmarking_file_path.unlink(missing_ok=True)
175+
for test_file in function_optimizer.test_files.get_by_type(TestType.EXISTING_UNIT_TEST).test_files:
176+
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
177+
test_file.benchmarking_file_path.unlink(missing_ok=True)
178+
for test_file in function_optimizer.test_files.get_by_type(TestType.CONCOLIC_COVERAGE_TEST).test_files:
179+
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
180+
171181
if is_successful(best_optimization):
172182
optimizations_found += 1
173183
else:
@@ -180,14 +190,6 @@ def run(self) -> None:
180190
elif self.args.all:
181191
logger.info("✨ All functions have been optimized! ✨")
182192
finally:
183-
for test_file in self.test_files.get_by_type(TestType.GENERATED_REGRESSION).test_files:
184-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
185-
test_file.benchmarking_file_path.unlink(missing_ok=True)
186-
for test_file in self.test_files.get_by_type(TestType.EXISTING_UNIT_TEST).test_files:
187-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
188-
test_file.benchmarking_file_path.unlink(missing_ok=True)
189-
for test_file in self.test_files.get_by_type(TestType.CONCOLIC_COVERAGE_TEST).test_files:
190-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
191193
if hasattr(get_run_tmp_file, "tmpdir"):
192194
get_run_tmp_file.tmpdir.cleanup()
193195
if self.test_cfg.concolic_test_root_dir:

0 commit comments

Comments
 (0)