diff options
author | Benjamin Peterson <benjamin@python.org> | 2018-01-30 06:02:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-30 06:02:09 (GMT) |
commit | 88fa79a10a340439ed021fbc4988b6f3e73b2391 (patch) | |
tree | 688fba5d72a49c0eccadb16379dc9490713ce271 | |
parent | 05f91a42cd9575ef338a67bd04855b44f6ac20c2 (diff) | |
download | cpython-88fa79a10a340439ed021fbc4988b6f3e73b2391.zip cpython-88fa79a10a340439ed021fbc4988b6f3e73b2391.tar.gz cpython-88fa79a10a340439ed021fbc4988b6f3e73b2391.tar.bz2 |
[3.6] replace dynamic import with 'exec' with importlib.import_module (GH-5433) (GH-5440)
(cherry picked from commit 77526f05fa788d6fb12f2121fe6b96c130d9b717)
-rw-r--r-- | Lib/test/test_hashlib.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 9817488..2861349 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -9,6 +9,7 @@ import array from binascii import unhexlify import hashlib +import importlib import itertools import os import sys @@ -86,11 +87,11 @@ class HashLibTestCase(unittest.TestCase): def _conditional_import_module(self, module_name): """Import a module and return a reference to it or None on failure.""" try: - exec('import '+module_name) - except ImportError as error: + return importlib.import_module(module_name) + except ModuleNotFoundError as error: if self._warn_on_extension_import: warnings.warn('Did a C extension fail to compile? %s' % error) - return locals().get(module_name) + return None def __init__(self, *args, **kwargs): algorithms = set() |