From 8308dd2ad4286ac3c9e882913451e9e517a0a238 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 24 Jul 2018 17:43:59 -0600 Subject: Quiet UtilTest ResourceWarning Use context manager around file opens to quiet a Python 3 resource leak warning. Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + src/engine/SCons/UtilTests.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index e3a646c..26ed803 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -103,6 +103,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - 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) + - quiet warning in UtilTests.py From Hao Wu - typo in customized decider example in user guide diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 842d4d8..81ec09d 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -488,8 +488,10 @@ class UtilTestCase(unittest.TestCase): filename = tempfile.mktemp() str = '1234567890 ' + filename try: - open(filename, 'w').write(str) - assert open(get_native_path(filename)).read() == str + with open(filename, 'w') as f: + f.write(str) + with open(get_native_path(filename)) as f: + assert f.read() == str finally: try: os.unlink(filename) -- cgit v0.12