Commit c0b1e0f8 authored by Victor Stinner's avatar Victor Stinner

Issue #24675: Avoid DeprecationWarning in test_os

Patch written by Martin Panter. I replace tearDown() with addCleanup().
parent 239aba78
...@@ -361,12 +361,18 @@ class UtimeTests(unittest.TestCase): ...@@ -361,12 +361,18 @@ class UtimeTests(unittest.TestCase):
with open(self.fname, 'wb') as fp: with open(self.fname, 'wb') as fp:
fp.write(b"ABC") 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 # ensure that st_atime and st_mtime are float
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
old_state = os.stat_float_times(-1) old_float_times = os.stat_float_times(-1)
self.addCleanup(os.stat_float_times, old_state) self.addCleanup(restore_float_times, old_float_times)
os.stat_float_times(True) os.stat_float_times(True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment