[Python-checkins] r86871 - python/branches/pep-382/Lib/test/test_pep382.py

martin.v.loewis python-checkins at python.org
Mon Nov 29 22:36:14 CET 2010


Author: martin.v.loewis
Date: Mon Nov 29 22:36:13 2010
New Revision: 86871

Log:
Move cleanup into finally block.


Modified:
   python/branches/pep-382/Lib/test/test_pep382.py

Modified: python/branches/pep-382/Lib/test/test_pep382.py
==============================================================================
--- python/branches/pep-382/Lib/test/test_pep382.py	(original)
+++ python/branches/pep-382/Lib/test/test_pep382.py	Mon Nov 29 22:36:13 2010
@@ -19,11 +19,12 @@
     original_value = sys.path_importer_cache.copy()
     original_object = sys.path_importer_cache
 
-    yield
-
-    sys.path_importer_cache = original_object
-    sys.path_importer_cache.clear()
-    sys.path_importer_cache.update(original_value)
+    try:
+        yield
+    finally:
+        sys.path_importer_cache = original_object
+        sys.path_importer_cache.clear()
+        sys.path_importer_cache.update(original_value)
 
 
 @contextlib.contextmanager
@@ -38,12 +39,12 @@
     for key in matching_modules():
         assert False, '{} already in sys.modules'.format(key)
 
-    yield
-
-    # delete all matching modules
-    for key in matching_modules():
-        del sys.modules[key]
-
+    try:
+        yield
+    finally:
+        # delete all matching modules
+        for key in matching_modules():
+            del sys.modules[key]
 
 class PthTestsBase(unittest.TestCase):
     """Try various combinations of __init__ and .pth files.


More information about the Python-checkins mailing list