@@ -130,19 +130,19 @@ def test_dtype_and_names_error(c_parser_only):
130130 ],
131131 ids = ["dt64-0" , "dt64-1" , "td64" , f"{ tm .ENDIAN } U8" ],
132132)
133- def test_unsupported_dtype (c_parser_only , match , kwargs ):
133+ def test_unsupported_dtype (c_parser_only , match , kwargs , tmp_path ):
134134 parser = c_parser_only
135135 df = DataFrame (
136136 np .random .default_rng (2 ).random ((5 , 2 )),
137137 columns = list ("AB" ),
138138 index = ["1A" , "1B" , "1C" , "1D" , "1E" ],
139139 )
140140
141- with tm . ensure_clean ( "__unsupported_dtype__.csv" ) as path :
142- df .to_csv (path )
141+ path = tmp_path / "__unsupported_dtype__.csv"
142+ df .to_csv (path )
143143
144- with pytest .raises (TypeError , match = match ):
145- parser .read_csv (path , index_col = 0 , ** kwargs )
144+ with pytest .raises (TypeError , match = match ):
145+ parser .read_csv (path , index_col = 0 , ** kwargs )
146146
147147
148148@td .skip_if_32bit
@@ -563,27 +563,27 @@ def test_file_handles_mmap(c_parser_only, csv1):
563563 assert not m .closed
564564
565565
566- def test_file_binary_mode (c_parser_only ):
566+ def test_file_binary_mode (c_parser_only , temp_file ):
567567 # see gh-23779
568568 parser = c_parser_only
569569 expected = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
570570
571- with tm . ensure_clean () as path :
572- with open (path , "w" , encoding = "utf-8" ) as f :
573- f .write ("1,2,3\n 4,5,6" )
571+ path = temp_file
572+ with open (path , "w" , encoding = "utf-8" ) as f :
573+ f .write ("1,2,3\n 4,5,6" )
574574
575- with open (path , "rb" ) as f :
576- result = parser .read_csv (f , header = None )
577- tm .assert_frame_equal (result , expected )
575+ with open (path , "rb" ) as f :
576+ result = parser .read_csv (f , header = None )
577+ tm .assert_frame_equal (result , expected )
578578
579579
580- def test_unix_style_breaks (c_parser_only ):
580+ def test_unix_style_breaks (c_parser_only , temp_file ):
581581 # GH 11020
582582 parser = c_parser_only
583- with tm . ensure_clean () as path :
584- with open (path , "w" , newline = "\n " , encoding = "utf-8" ) as f :
585- f .write ("blah\n \n col_1,col_2,col_3\n \n " )
586- result = parser .read_csv (path , skiprows = 2 , encoding = "utf-8" , engine = "c" )
583+ path = temp_file
584+ with open (path , "w" , newline = "\n " , encoding = "utf-8" ) as f :
585+ f .write ("blah\n \n col_1,col_2,col_3\n \n " )
586+ result = parser .read_csv (path , skiprows = 2 , encoding = "utf-8" , engine = "c" )
587587 expected = DataFrame (columns = ["col_1" , "col_2" , "col_3" ])
588588 tm .assert_frame_equal (result , expected )
589589
0 commit comments