]> granicus.if.org Git - python/commitdiff
Silence ResourceWarning when testing that the file destructor closes the file.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:53:03 +0000 (23:53 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:53:03 +0000 (23:53 +0000)
Lib/test/test_io.py

index 7ce9753a389149b93c796596bb1c6eebf6c8736c..d1973e5f3ee308b2e2f46413a8db0395aded9133 100644 (file)
@@ -461,13 +461,14 @@ class IOTest(unittest.TestCase):
             def flush(self):
                 record.append(3)
                 super().flush()
-        f = MyFileIO(support.TESTFN, "wb")
-        f.write(b"xxx")
-        del f
-        support.gc_collect()
-        self.assertEqual(record, [1, 2, 3])
-        with self.open(support.TESTFN, "rb") as f:
-            self.assertEqual(f.read(), b"xxx")
+        with support.check_warnings(('', ResourceWarning)):
+            f = MyFileIO(support.TESTFN, "wb")
+            f.write(b"xxx")
+            del f
+            support.gc_collect()
+            self.assertEqual(record, [1, 2, 3])
+            with self.open(support.TESTFN, "rb") as f:
+                self.assertEqual(f.read(), b"xxx")
 
     def _check_base_destructor(self, base):
         record = []