From ca276f452540f68c08cb3df9049e9e7876364dac Mon Sep 17 00:00:00 2001 From: spisarski Date: Thu, 27 Jul 2017 10:27:14 -0600 Subject: Ensure library and tests close all necessary resources. The SNAPS-OO library and tests had left open files, ssh, and scp connections. These have all now been wrapped with try/finally blocks. JIRA: SNAPS-152 Change-Id: I43e09978b5c075bd78ff3279c0799556b8758878 Signed-off-by: spisarski --- snaps/tests/file_utils_tests.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'snaps/tests/file_utils_tests.py') diff --git a/snaps/tests/file_utils_tests.py b/snaps/tests/file_utils_tests.py index f3a622a..ef8b4ae 100644 --- a/snaps/tests/file_utils_tests.py +++ b/snaps/tests/file_utils_tests.py @@ -37,10 +37,14 @@ class FileUtilsTests(unittest.TestCase): os.makedirs(self.test_dir) self.tmpFile = self.test_dir + '/bar.txt' + self.tmp_file_opened = None if not os.path.exists(self.tmpFile): - open(self.tmpFile, 'wb') + self.tmp_file_opened = open(self.tmpFile, 'wb') def tearDown(self): + if self.tmp_file_opened: + self.tmp_file_opened.close() + if os.path.exists(self.test_dir) and os.path.isdir(self.test_dir): shutil.rmtree(self.tmp_dir) -- cgit 1.2.3-korg