From 4e89ab2e66f3fb78c92e3060507f1a50a5a74d69 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 26 Jan 2021 10:06:57 -0500 Subject: [PATCH] Context manager. --- integration/test_sftp.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/integration/test_sftp.py b/integration/test_sftp.py index ed5b37a31..6171c7413 100644 --- a/integration/test_sftp.py +++ b/integration/test_sftp.py @@ -101,15 +101,14 @@ def test_ssh_key_auth(alice): def test_read_write_files(alice): """It's possible to upload and download files.""" sftp = connect_sftp() - f = sftp.file("myfile", "wb") - f.write(b"abc") - f.write(b"def") - f.close() - f = sftp.file("myfile", "rb") - assert f.read(4) == b"abcd" - assert f.read(2) == b"ef" - assert f.read(1) == b"" - f.close() + with sftp.file("myfile", "wb") as f: + f.write(b"abc") + f.write(b"def") + + with sftp.file("myfile", "rb") as f: + assert f.read(4) == b"abcd" + assert f.read(2) == b"ef" + assert f.read(1) == b"" @run_in_thread