diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 6581e350d01..2e23615e89b 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -430,12 +430,18 @@ def setUp(self): 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)