Commits

Victor Stinner committed b538445

test_codecs now removes the temporay file (created by the test)

  • Participants
  • Parent commits 9ef8fc5
  • Branches 3.1

Comments (0)

Files changed (1)

File Lib/test/test_codecs.py

         s1 = 'Hello\r\nworld\r\n'
 
         s = s1.encode(self.encoding)
-        try:
-            with open(support.TESTFN, 'wb') as fp:
-                fp.write(s)
-            with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
-                self.assertEqual(reader.read(), s1)
-        finally:
-            support.unlink(support.TESTFN)
+        self.addCleanup(support.unlink, support.TESTFN)
+        with open(support.TESTFN, 'wb') as fp:
+            fp.write(s)
+        with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
+            self.assertEqual(reader.read(), s1)
 
 class UTF16LETest(ReadTest):
     encoding = "utf-16-le"
                  "utf-32",
                  "utf-32-le",
                  "utf-32-be")
+        self.addCleanup(support.unlink, support.TESTFN)
         for encoding in tests:
             # Check if the BOM is written only once
             with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f: