Skip to content

Commit 827dd54

Browse files
committed
Update test_instrument_tests.py
1 parent 1373696 commit 827dd54

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
@@ -157,24 +157,25 @@ def test_sort(self):
157157
self.assertEqual(codeflash_wrap(sorter, '{module_path}', 'TestPigLatin', 'test_sort', 'sorter', '7', codeflash_loop_index, codeflash_cur, codeflash_con, input), list(range(5000)))
158158
codeflash_con.close()
159159
"""
160-
with tempfile.NamedTemporaryFile(mode="w") as f:
161-
f.write(code)
162-
f.flush()
163-
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=Path(f.name))
160+
with tempfile.TemporaryDirectory() as tempdir:
161+
temp_file_path = Path(tempdir) / "temp_test.py"
162+
with temp_file_path.open("w") as f:
163+
f.write(code)
164+
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=temp_file_path)
164165
original_cwd = Path.cwd()
165166
run_cwd = Path(__file__).parent.parent.resolve()
166167
os.chdir(run_cwd)
167168
success, new_test = inject_profiling_into_existing_test(
168-
Path(f.name),
169+
temp_file_path,
169170
[CodePosition(9, 17), CodePosition(13, 17), CodePosition(17, 17)],
170171
func,
171-
Path(f.name).parent,
172+
temp_file_path.parent,
172173
"unittest",
173174
)
174175
os.chdir(original_cwd)
175176
assert success
176177
assert new_test == expected.format(
177-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
178+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
178179
)
179180

180181

0 commit comments

Comments
 (0)