File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -1940,7 +1940,14 @@ def create_file_stream(length: int) -> io.IOBase:
19401940 f .write (os .urandom (length ))
19411941
19421942 stream = open (temp_file , "rb" )
1943- stream .delete_temp_file = lambda : os .remove (temp_file )
1943+
1944+ def cleanup ():
1945+ try :
1946+ stream .close ()
1947+ finally :
1948+ os .remove (temp_file )
1949+
1950+ stream .cleanup = lambda : cleanup ()
19441951 return stream
19451952
19461953
@@ -1965,13 +1972,13 @@ def create_file_stream(length: int) -> io.IOBase:
19651972 "File stream: length reported" ,
19661973 contents = lambda : create_file_stream (566 ),
19671974 expected_content_length = 566 ,
1968- cleanup = lambda stream : stream .delete_temp_file (),
1975+ cleanup = lambda stream : stream .cleanup (),
19691976 ),
19701977 SingleShotUploadContentLengthTestCase (
19711978 "File stream with tell disabled: length unknown" ,
19721979 contents = lambda : make_non_seekable (create_file_stream (239 ), disable_tell = True ),
19731980 expected_content_length = None ,
1974- cleanup = lambda stream : stream .delete_temp_file (),
1981+ cleanup = lambda stream : stream .cleanup (),
19751982 ),
19761983 ],
19771984 ids = SingleShotUploadContentLengthTestCase .to_string ,
You can’t perform that action at this time.
0 commit comments