]> granicus.if.org Git - python/commitdiff
Issue #17384: Consolidated cleanup operations in tests.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 8 Mar 2013 09:50:57 +0000 (09:50 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 8 Mar 2013 09:50:57 +0000 (09:50 +0000)
Lib/test/test_logging.py

index bfa7d772f42c312623e453395467086e25ce7dd5..0981704b0a37bf31c0661244357c2fb56b32a880 100644 (file)
@@ -3396,6 +3396,12 @@ class BasicConfigTest(unittest.TestCase):
         self.assertEqual(logging.root.level, self.original_logging_level)
 
     def test_filename(self):
+
+        def cleanup(h1, h2, fn):
+            h1.close()
+            h2.close()
+            os.remove(fn)
+
         logging.basicConfig(filename='test.log')
 
         self.assertEqual(len(logging.root.handlers), 1)
@@ -3403,19 +3409,23 @@ class BasicConfigTest(unittest.TestCase):
         self.assertIsInstance(handler, logging.FileHandler)
 
         expected = logging.FileHandler('test.log', 'a')
-        self.addCleanup(expected.close)
         self.assertEqual(handler.stream.mode, expected.stream.mode)
         self.assertEqual(handler.stream.name, expected.stream.name)
-        self.addCleanup(os.remove, 'test.log')
+        self.addCleanup(cleanup, handler, expected, 'test.log')
 
     def test_filemode(self):
+
+        def cleanup(h1, h2, fn):
+            h1.close()
+            h2.close()
+            os.remove(fn)
+
         logging.basicConfig(filename='test.log', filemode='wb')
 
         handler = logging.root.handlers[0]
         expected = logging.FileHandler('test.log', 'wb')
-        self.addCleanup(expected.close)
         self.assertEqual(handler.stream.mode, expected.stream.mode)
-        self.addCleanup(os.remove, 'test.log')
+        self.addCleanup(cleanup, handler, expected, 'test.log')
 
     def test_stream(self):
         stream = io.StringIO()