@@ -97,25 +97,25 @@ def test_nonexistent_path(all_parsers):
9797
9898@pytest .mark .skipif (WASM , reason = "limited file system access on WASM" ) 
9999@td .skip_if_windows   # os.chmod does not work in windows  
100- def  test_no_permission (all_parsers ):
100+ def  test_no_permission (all_parsers ,  temp_file ):
101101    # GH 23784 
102102    parser  =  all_parsers 
103103
104104    msg  =  r"\[Errno 13\]" 
105-     with   tm . ensure_clean ()  as   path : 
106-          os .chmod (path , 0 )  # make file unreadable 
105+     path   =   temp_file 
106+     os .chmod (path , 0 )  # make file unreadable 
107107
108-         # verify that this process cannot open the file (not running as sudo) 
109-         try :
110-             with  open (path , encoding = "utf-8" ):
111-                 pass 
112-             pytest .skip ("Running as sudo." )
113-         except  PermissionError :
108+     # verify that this process cannot open the file (not running as sudo) 
109+     try :
110+         with  open (path , encoding = "utf-8" ):
114111            pass 
112+         pytest .skip ("Running as sudo." )
113+     except  PermissionError :
114+         pass 
115115
116-          with  pytest .raises (PermissionError , match = msg ) as  e :
117-              parser .read_csv (path )
118-          assert  path  ==  e .value .filename 
116+     with  pytest .raises (PermissionError , match = msg ) as  e :
117+         parser .read_csv (path )
118+     assert  str ( path . resolve ())  ==  e .value .filename 
119119
120120
121121@pytest .mark .parametrize ( 
@@ -269,19 +269,19 @@ def test_internal_eof_byte(all_parsers):
269269    tm .assert_frame_equal (result , expected )
270270
271271
272- def  test_internal_eof_byte_to_file (all_parsers ):
272+ def  test_internal_eof_byte_to_file (all_parsers ,  temp_file ):
273273    # see gh-16559 
274274    parser  =  all_parsers 
275275    data  =  b'c1,c2\r \n "test \x1a     test", test\r \n ' 
276276    expected  =  DataFrame ([["test \x1a     test" , " test" ]], columns = ["c1" , "c2" ])
277277    path  =  f"__{ uuid .uuid4 ()}  __.csv" 
278278
279-     with   tm . ensure_clean ( path )  as  path : 
280-          with  open (path , "wb" ) as  f :
281-              f .write (data )
279+     path2   =   temp_file . parent   /  path 
280+     with  open (path2 , "wb" ) as  f :
281+         f .write (data )
282282
283-          result  =  parser .read_csv (path )
284-          tm .assert_frame_equal (result , expected )
283+     result  =  parser .read_csv (path2 )
284+     tm .assert_frame_equal (result , expected )
285285
286286
287287def  test_file_handle_string_io (all_parsers ):
@@ -372,7 +372,7 @@ def test_read_csv_file_handle(all_parsers, io_class, encoding):
372372    assert  not  handle .closed 
373373
374374
375- def  test_memory_map_compression (all_parsers , compression ):
375+ def  test_memory_map_compression (all_parsers , compression ,  temp_file ):
376376    """ 
377377    Support memory map for compressed files. 
378378
@@ -381,16 +381,16 @@ def test_memory_map_compression(all_parsers, compression):
381381    parser  =  all_parsers 
382382    expected  =  DataFrame ({"a" : [1 ], "b" : [2 ]})
383383
384-     with   tm . ensure_clean ()  as   path : 
385-          expected .to_csv (path , index = False , compression = compression )
384+     path   =   temp_file 
385+     expected .to_csv (path , index = False , compression = compression )
386386
387-          if  parser .engine  ==  "pyarrow" :
388-              msg  =  "The 'memory_map' option is not supported with the 'pyarrow' engine" 
389-              with  pytest .raises (ValueError , match = msg ):
390-                  parser .read_csv (path , memory_map = True , compression = compression )
391-              return 
387+     if  parser .engine  ==  "pyarrow" :
388+         msg  =  "The 'memory_map' option is not supported with the 'pyarrow' engine" 
389+         with  pytest .raises (ValueError , match = msg ):
390+             parser .read_csv (path , memory_map = True , compression = compression )
391+         return 
392392
393-          result  =  parser .read_csv (path , memory_map = True , compression = compression )
393+     result  =  parser .read_csv (path , memory_map = True , compression = compression )
394394
395395    tm .assert_frame_equal (
396396        result ,
@@ -442,12 +442,12 @@ def test_context_manageri_user_provided(all_parsers, datapath):
442442
443443
444444@skip_pyarrow   # ParserError: Empty CSV file  
445- def  test_file_descriptor_leak (all_parsers ):
445+ def  test_file_descriptor_leak (all_parsers ,  temp_file ):
446446    # GH 31488 
447447    parser  =  all_parsers 
448-     with   tm . ensure_clean ()  as   path : 
449-          with  pytest .raises (EmptyDataError , match = "No columns to parse from file" ):
450-              parser .read_csv (path )
448+     path   =   temp_file 
449+     with  pytest .raises (EmptyDataError , match = "No columns to parse from file" ):
450+         parser .read_csv (path )
451451
452452
453453def  test_memory_map (all_parsers , csv_dir_path ):
0 commit comments