@@ -33,12 +33,13 @@ def test_sort(self):
3333 tests_project_rootdir = cur_dir_path .parent ,
3434 )
3535
36- with tempfile .NamedTemporaryFile (prefix = "test_xx" , suffix = ".py" , dir = cur_dir_path ) as fp :
36+ with tempfile .TemporaryDirectory (dir = cur_dir_path ) as tempdir :
37+ temp_file_path = Path (tempdir ) / "test_xx.py"
3738 test_files = TestFiles (
38- test_files = [TestFile (instrumented_behavior_file_path = Path ( fp . name ) , test_type = TestType .EXISTING_UNIT_TEST )]
39+ test_files = [TestFile (instrumented_behavior_file_path = temp_file_path , test_type = TestType .EXISTING_UNIT_TEST )]
3940 )
40- fp . write ( code . encode ( " utf-8" ))
41- fp .flush ( )
41+ with open ( temp_file_path , "w" , encoding = " utf-8" ) as fp :
42+ fp .write ( code )
4243 result_file , process , _ , _ = run_behavioral_tests (
4344 test_files ,
4445 test_framework = config .test_framework ,
@@ -77,12 +78,13 @@ def test_sort():
7778 else :
7879 test_env ["PYTHONPATH" ] += os .pathsep + str (config .project_root_path )
7980
80- with tempfile .NamedTemporaryFile (prefix = "test_xx" , suffix = ".py" , dir = cur_dir_path ) as fp :
81+ with tempfile .TemporaryDirectory (dir = cur_dir_path ) as tempdir :
82+ temp_file_path = Path (tempdir ) / "test_xx.py"
8183 test_files = TestFiles (
82- test_files = [TestFile (instrumented_behavior_file_path = Path ( fp . name ) , test_type = TestType .EXISTING_UNIT_TEST )]
84+ test_files = [TestFile (instrumented_behavior_file_path = temp_file_path , test_type = TestType .EXISTING_UNIT_TEST )]
8385 )
84- fp . write ( code . encode ( " utf-8" ))
85- fp .flush ( )
86+ with open ( temp_file_path , "w" , encoding = " utf-8" ) as fp :
87+ fp .write ( code )
8688 result_file , process , _ , _ = run_behavioral_tests (
8789 test_files ,
8890 test_framework = config .test_framework ,
0 commit comments