Author: Manuel Jacob <[email protected]>
Branch: 
Changeset: r82574:b9f8538d63ca
Date: 2016-02-26 22:21 +0100
http://bitbucket.org/pypy/pypy/changeset/b9f8538d63ca/

Log:    Use try / finally to remove module even in case of an exception.

diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -652,11 +652,13 @@
         # one in sys.path.
         import sys
         assert '_md5' not in sys.modules
-        import _md5
-        assert hasattr(_md5, 'hello_world')
-        assert not hasattr(_md5, 'digest_size')
-        assert '(built-in)' not in repr(_md5)
-        del sys.modules['_md5']
+        try:
+            import _md5
+            assert hasattr(_md5, 'hello_world')
+            assert not hasattr(_md5, 'digest_size')
+            assert '(built-in)' not in repr(_md5)
+        finally:
+            sys.modules.pop('_md5', None)
 
     def test_shadow_extension_2(self):
         if self.runappdirect: skip("hard to test: module is already imported")
@@ -675,7 +677,7 @@
             assert '(built-in)' in repr(_md5)
         finally:
             sys.path.insert(0, sys.path.pop())
-        del sys.modules['_md5']
+            sys.modules.pop('_md5', None)
 
     def test_invalid_pathname(self):
         import imp
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to