Skip to content

Commit a780bba

Browse files
committed
Close stream before deleting the file
1 parent 3a443d9 commit a780bba

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/test_files.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)