From d1a1def7bf221b04dcf3fc3a67aa19aa2f622f83 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 28 Apr 2017 19:17:26 +0300 Subject: bpo-30197: Enhance functions swap_attr() and swap_item() in test.support. (#1341) * bpo-30197: Enhance functions swap_attr() and swap_item() in test.support. They now work when delete replaced attribute or item inside the with statement. The old value of the attribute or item (or None if it doesn't exist) now will be assigned to the target of the "as" clause, if there is one. * Update docstrings. --- Lib/test/test_tempfile.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib/test/test_tempfile.py') diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 51df1ecd7d..d0cf04b0cb 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -273,13 +273,12 @@ class TestGetDefaultTempdir(BaseTestCase): tempfile._get_default_tempdir() self.assertEqual(os.listdir(our_temp_directory), []) - open = io.open def bad_writer(*args, **kwargs): - fp = open(*args, **kwargs) + fp = orig_open(*args, **kwargs) fp.write = raise_OSError return fp - with support.swap_attr(io, "open", bad_writer): + with support.swap_attr(io, "open", bad_writer) as orig_open: # test again with failing write() with self.assertRaises(FileNotFoundError): tempfile._get_default_tempdir() -- cgit v1.2.1