From c0b1e0f868a8688b49399ec83c05bc318bb90916 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jul 2015 17:12:57 +0200 Subject: [PATCH] Issue #24675: Avoid DeprecationWarning in test_os Patch written by Martin Panter. I replace tearDown() with addCleanup(). --- Lib/test/test_os.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 0d49b99341c..adedcd94272 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -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)