mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #24675: Avoid DeprecationWarning in test_os
Patch written by Martin Panter. I replace tearDown() with addCleanup().
This commit is contained in:
parent
239aba7874
commit
c0b1e0f868
1 changed files with 8 additions and 2 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue