]> granicus.if.org Git - python/commitdiff
bpo-33760: Fix file leaks in test_io. (GH-7361)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 4 Jun 2018 02:53:56 +0000 (05:53 +0300)
committerNed Deily <nad@python.org>
Mon, 4 Jun 2018 02:53:56 +0000 (22:53 -0400)
Lib/test/test_io.py

index 343c5a444072841e63b67d6378b153d3d2996dee..286ae760e17fcbeafb9a1e2fe6733c6f79256995 100644 (file)
@@ -1516,6 +1516,7 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
     def test_garbage_collection(self):
         # C BufferedReader objects are collected.
         # The Python version has __del__, so it ends into gc.garbage instead
+        self.addCleanup(support.unlink, support.TESTFN)
         with support.check_warnings(('', ResourceWarning)):
             rawio = self.FileIO(support.TESTFN, "w+b")
             f = self.tp(rawio)
@@ -1718,6 +1719,7 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
 
     def test_truncate(self):
         # Truncate implicitly flushes the buffer.
+        self.addCleanup(support.unlink, support.TESTFN)
         with self.open(support.TESTFN, self.write_mode, buffering=0) as raw:
             bufio = self.tp(raw, 8)
             bufio.write(b"abcdef")
@@ -1730,6 +1732,7 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
         # Ensure that truncate preserves the file position after
         # writes longer than the buffer size.
         # Issue: https://bugs.python.org/issue32228
+        self.addCleanup(support.unlink, support.TESTFN)
         with self.open(support.TESTFN, "wb") as f:
             # Fill with some buffer
             f.write(b'\x00' * 10000)
@@ -1851,6 +1854,7 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
         # C BufferedWriter objects are collected, and collecting them flushes
         # all data to disk.
         # The Python version has __del__, so it ends into gc.garbage instead
+        self.addCleanup(support.unlink, support.TESTFN)
         with support.check_warnings(('', ResourceWarning)):
             rawio = self.FileIO(support.TESTFN, "w+b")
             f = self.tp(rawio)