def get_temp_file(self, prefix=template, suffix=""):
"""
On windows we cannot open temporary files after creating them unless we close them first.
For this reason we must also create them with delete=False (or they would be deleted immediately when closed)
and we want to make sure that the test object owns a reference to the file objects by adding them
to self._tempfiles, so that they can be deleted when the test finishes.
"""
ret = NamedTemporaryFile(delete=False, prefix=prefix, suffix=suffix)
self._tempfiles.append(ret)
if is_win():
ret.close()
return ret
评论列表
文章目录