From dfb1fd71fe07f286e98e9035996ffa8dbd9350be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Thu, 10 Aug 2017 10:30:25 +0200 Subject: [PATCH] utils.archive: Properly close the opened file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On python3 this naked open reports ResourceWarning. Let's properly close it: avocado/utils/archive.py:191: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/avocado___main__rv2ihor0/tmp0drzyrsb/ link_to_file2' mode='r' encoding='UTF-8'> src = open(dst, 'r').read() Signed-off-by: Lukáš Doktor --- avocado/utils/archive.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avocado/utils/archive.py b/avocado/utils/archive.py index f3d713c3..4a8bef1f 100644 --- a/avocado/utils/archive.py +++ b/avocado/utils/archive.py @@ -186,7 +186,8 @@ class ArchiveFile(object): dst = os.path.join(dst_dir, path) if not os.path.islink(dst): # Link created as an ordinary file containing the dst path - src = open(dst, 'r').read() + with open(dst, 'r') as dst_path: + src = dst_path.read() else: # Link is already there and could be outdated. Let's read # the original destination from the zip file. -- GitLab