From 2cca0572848817791537efc9ee5df66d4ceb2d42 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 23 May 2011 14:51:42 +0200 Subject: [PATCH] test_codecs now removes the temporay file (created by the test) --- Lib/test/test_codecs.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 93cdf915b8..e412a6444e 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -515,13 +515,11 @@ class UTF16Test(ReadTest): 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" @@ -1628,6 +1626,7 @@ class BomTest(unittest.TestCase): "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: -- 2.40.0