]> granicus.if.org Git - python/commitdiff
Issue #24675: Avoid DeprecationWarning in test_os
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 20 Jul 2015 15:12:57 +0000 (17:12 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 20 Jul 2015 15:12:57 +0000 (17:12 +0200)
Patch written by Martin Panter. I replace tearDown() with addCleanup().

Lib/test/test_os.py

index 0d49b99341cc34edec34413a70fa99cec5f41b5f..adedcd94272aed168dbc2d31b0042dd062860e79 100644 (file)
@@ -361,12 +361,18 @@ class UtimeTests(unittest.TestCase):
         with open(self.fname, 'wb') as fp:
             fp.write(b"ABC")
 
+        def restore_float_times(state):
+            with warnings.catch_warnings():
+                warnings.simplefilter("ignore", DeprecationWarning)
+
+                os.stat_float_times(state)
+
         # ensure that st_atime and st_mtime are float
         with warnings.catch_warnings():
             warnings.simplefilter("ignore", DeprecationWarning)
 
-            old_state = os.stat_float_times(-1)
-            self.addCleanup(os.stat_float_times, old_state)
+            old_float_times = os.stat_float_times(-1)
+            self.addCleanup(restore_float_times, old_float_times)
 
             os.stat_float_times(True)