Skip to content

Commit 86199c4

Browse files
committed
Update test_instrument_tests.py
1 parent 5830d98 commit 86199c4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tests/test_instrument_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,25 @@ def test_sort(self):
164164
self.assertEqual(codeflash_wrap(sorter, '{module_path}', 'TestPigLatin', 'test_sort', 'sorter', '7', codeflash_loop_index, codeflash_cur, codeflash_con, input), list(range(5000)))
165165
codeflash_con.close()
166166
"""
167-
with tempfile.NamedTemporaryFile(mode="w") as f:
168-
f.write(code)
169-
f.flush()
170-
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=Path(f.name))
167+
with tempfile.TemporaryDirectory() as tempdir:
168+
temp_file_path = Path(tempdir) / "temp_test.py"
169+
with temp_file_path.open("w") as f:
170+
f.write(code)
171+
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=temp_file_path)
171172
original_cwd = Path.cwd()
172173
run_cwd = Path(__file__).parent.parent.resolve()
173174
os.chdir(run_cwd)
174175
success, new_test = inject_profiling_into_existing_test(
175-
Path(f.name),
176+
temp_file_path,
176177
[CodePosition(9, 17), CodePosition(13, 17), CodePosition(17, 17)],
177178
func,
178-
Path(f.name).parent,
179+
temp_file_path.parent,
179180
"unittest",
180181
)
181182
os.chdir(original_cwd)
182183
assert success
183184
assert new_test == expected.format(
184-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
185+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
185186
)
186187

187188

0 commit comments

Comments
 (0)