[lang-ref] ( temp_file ) ( python )

def test_temp_file():
    # tempfile.NamedTemporaryFile
    with tempfile.NamedTemporaryFile() as f:
        assert isinstance(f.file, io.IOBase)
        assert f.name.startswith('/var/')
def test_temp_file_alternative():
    # tempfile.mkstemp()
    fd, path = tempfile.mkstemp()
    try:
        os.write(fd, b"hello")
    finally:
        os.close(fd)
        os.unlink(path)