summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPhilip Roche <phil.roche@canonical.com>2019-07-29 16:40:33 +0100
committerPhilip Roche <phil.roche@canonical.com>2019-07-29 16:40:33 +0100
commit1e901d921db174d897d8732e9394f07effdad20d (patch)
tree61bd2f40b0f6539c8b31dc9f46f73dd47eb30ba2 /tests
parent1d48093fe91344af6e921f14dec42fc5d2718be4 (diff)
downloadpython-jenkins-job-builder-1e901d921db174d897d8732e9394f07effdad20d.tar.gz
python-jenkins-job-builder-1e901d921db174d897d8732e9394f07effdad20d.tar.xz
python-jenkins-job-builder-1e901d921db174d897d8732e9394f07effdad20d.zip
Avoid ResourceWarning by closing file handlers when finished
Warnings appear when running local_yaml unit tests. This commit fixes the issues causing these warnings ``` ResourceWarning: unclosed file <_io.TextIOWrapper name='jenkins-job-builder/tests/yamlparser/fixtures/include_path001.conf' mode='r' encoding='utf-8'> jjb_config = JJBConfig(self.conf_filename) ``` Change-Id: I8fec288cce8c9f6c7b928886d7c70f7a35d43b4a
Diffstat (limited to 'tests')
-rw-r--r--tests/base.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/base.py b/tests/base.py
index 514b83c4..b239f64e 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -137,7 +137,8 @@ class BaseTestCase(testtools.TestCase):
# Read XML content, assuming it is unicode encoded
xml_content = ""
for f in sorted(self.out_filenames):
- xml_content += u"%s" % io.open(f, 'r', encoding='utf-8').read()
+ with io.open(f, 'r', encoding='utf-8') as xml_file:
+ xml_content += u"%s" % xml_file.read()
return xml_content
def _read_yaml_content(self, filename):