Skip to content

Commit 0e90f7a

Browse files
committed
Update test_instrument_tests.py
1 parent cc84732 commit 0e90f7a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/test_instrument_tests.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import tempfile
88
from pathlib import Path
9-
9+
import pytest
1010
from codeflash.code_utils.code_utils import get_run_tmp_file
1111
from codeflash.code_utils.instrument_existing_tests import (
1212
FunctionImportedAsVisitor,
@@ -85,9 +85,13 @@
8585
raise exception
8686
return return_value
8787
"""
88+
# create a temporary directory for the test results
89+
@pytest.fixture
90+
def tmp_dir():
91+
with tempfile.TemporaryDirectory() as tmpdirname:
92+
yield Path(tmpdirname)
8893

89-
90-
def test_perfinjector_bubble_sort() -> None:
94+
def test_perfinjector_bubble_sort(tmp_dir) -> None:
9195
code = """import unittest
9296
9397
from code_to_optimize.bubble_sort import sorter
@@ -169,7 +173,8 @@ def test_sort(self):
169173
self.assertEqual(codeflash_wrap(sorter, '{module_path}', 'TestPigLatin', 'test_sort', 'sorter', '7', codeflash_loop_index, codeflash_cur, codeflash_con, input), list(range(5000)))
170174
codeflash_con.close()
171175
"""
172-
with tempfile.NamedTemporaryFile(mode="w") as f:
176+
177+
with (tmp_dir / "test_sort.py").open("w") as f:
173178
f.write(code)
174179
f.flush()
175180
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=Path(f.name))
@@ -186,7 +191,7 @@ def test_sort(self):
186191
os.chdir(original_cwd)
187192
assert success
188193
assert new_test.replace('"', "'") == expected.format(
189-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
194+
module_path=Path(f.name).stem, tmp_dir_path=get_run_tmp_file(Path("test_return_values")).as_posix()
190195
).replace('"', "'")
191196

192197

0 commit comments

Comments
 (0)