summaryrefslogtreecommitdiffstats
path: root/testing/framework
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2018-07-24 21:44:48 (GMT)
committerMats Wichmann <mats@linux.com>2018-07-24 21:44:48 (GMT)
commitbde85d7501235a67bee32c65f83a9e4da52e3968 (patch)
treee0f510ce55a263c0cdc603a758d8e126899a399d /testing/framework
parentee03bf12b40248e89ada1e501cf52b9b7cd9f867 (diff)
downloadSCons-bde85d7501235a67bee32c65f83a9e4da52e3968.zip
SCons-bde85d7501235a67bee32c65f83a9e4da52e3968.tar.gz
SCons-bde85d7501235a67bee32c65f83a9e4da52e3968.tar.bz2
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 <mats@linux.com>
Diffstat (limited to 'testing/framework')
-rw-r--r--testing/framework/TestCmd.py6
1 files changed, 4 insertions, 2 deletions
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.