[pypy-commit] pypy default: Use try / finally to remove module even in case of an exception.
mjacob
pypy.commits at gmail.com
Fri Feb 26 16:25:26 EST 2016
Author: Manuel Jacob <me at manueljacob.de>
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
More information about the pypy-commit
mailing list