From: Serhiy Storchaka <storchaka@gmail.com>
Date: Mon, 14 Oct 2013 17:09:47 +0000 (+0300)
Subject: Issue #18919: Fixed resource leaks in audio tests.
X-Git-Tag: v3.4.0a4~103^2
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85812bca211dda686666d4a88182d5f7587decbc;p=python

Issue #18919: Fixed resource leaks in audio tests.
---

diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py
index 147cda002a..59e9928796 100644
--- a/Lib/test/audiotests.py
+++ b/Lib/test/audiotests.py
@@ -141,18 +141,18 @@ class AudioTestsWithSourceFile(AudioTests):
                           self.sndfilenframes, self.comptype, self.compname)
 
     def test_close(self):
-        testfile = open(self.sndfilepath, 'rb')
-        f = self.f = self.module.open(testfile)
-        self.assertFalse(testfile.closed)
-        f.close()
-        self.assertEqual(testfile.closed, self.close_fd)
-        testfile = open(TESTFN, 'wb')
-        fout = self.module.open(testfile, 'wb')
-        self.assertFalse(testfile.closed)
-        with self.assertRaises(self.module.Error):
-            fout.close()
-        self.assertEqual(testfile.closed, self.close_fd)
-        fout.close() # do nothing
+        with open(self.sndfilepath, 'rb') as testfile:
+            f = self.f = self.module.open(testfile)
+            self.assertFalse(testfile.closed)
+            f.close()
+            self.assertEqual(testfile.closed, self.close_fd)
+        with open(TESTFN, 'wb') as testfile:
+            fout = self.fout = self.module.open(testfile, 'wb')
+            self.assertFalse(testfile.closed)
+            with self.assertRaises(self.module.Error):
+                fout.close()
+            self.assertEqual(testfile.closed, self.close_fd)
+            fout.close() # do nothing
 
     def test_read(self):
         framesize = self.nchannels * self.sampwidth