summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_hashlib.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2018-01-30 02:03:01 (GMT)
committerGregory P. Smith <greg@krypto.org>2018-01-30 02:03:01 (GMT)
commit77526f05fa788d6fb12f2121fe6b96c130d9b717 (patch)
treed5e6acd2298c7f55893d1eb495da941c89385d22 /Lib/test/test_hashlib.py
parent7f8bfc9b9a8381ddb768421b5dd5cbd970266190 (diff)
downloadcpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.zip
cpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.tar.gz
cpython-77526f05fa788d6fb12f2121fe6b96c130d9b717.tar.bz2
replace dynamic import with 'exec' with importlib.import_module (#5433)
Diffstat (limited to 'Lib/test/test_hashlib.py')
-rw-r--r--Lib/test/test_hashlib.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index e4e5280..15fc22b 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
@@ -83,11 +84,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()