From bde85d7501235a67bee32c65f83a9e4da52e3968 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 24 Jul 2018 15:44:48 -0600 Subject: Fix py3 ResourceWarning in TestCmd class TestCmd method read() uses a shortcut to return data from a file, "return open(...).read()". Python 3 warns this is a resource leak because the file has no chance to be closed with the open being in the return statement. Split into two lines and use a context manager (with statement). Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + testing/framework/TestCmd.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 79d25db..e3a646c 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -102,6 +102,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - xml validity fixes from SConstruct.py change - update wiki links to new github location - update bug links to new github location + - convert TestCmd.read to use with statement on open (quiets 17 py3 warnings) From Hao Wu - typo in customized decider example in user guide diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 9cd6b39..9499ff4 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -1247,9 +1247,11 @@ class TestCmd(object): if mode[0] != 'r': raise ValueError("mode must begin with 'r'") if IS_PY3 and 'b' not in mode: - return open(file, mode, newline=newline).read() + with open(file, mode, newline=newline) as f: + return f.read() else: - return open(file, mode).read() + with open(file, mode) as f: + return f.read() def rmdir(self, dir): """Removes the specified dir name. -- cgit v0.12