[Python-checkins] cpython (3.4): Issue #24675: Avoid DeprecationWarning in test_os

victor.stinner python-checkins at python.org
Mon Jul 20 17:13:47 CEST 2015


https://hg.python.org/cpython/rev/bc67e0030d42
changeset:   96961:bc67e0030d42
branch:      3.4
parent:      96956:efda1eaf86a3
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jul 20 17:12:57 2015 +0200
summary:
  Issue #24675: Avoid DeprecationWarning in test_os

Patch written by Martin Panter. I replace tearDown() with addCleanup().

files:
  Lib/test/test_os.py |  10 ++++++++--
  1 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -361,12 +361,18 @@
         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)
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list