def test_import_failure_from_module(self):
"""
Tests whether e.g. "import socketserver" succeeds in a module
imported by another module that has used and removed the stdlib hooks.
We want this to fail; the stdlib hooks should not bleed to imported
modules too without their explicitly invoking them.
"""
code1 = '''
from future import standard_library
standard_library.install_hooks()
standard_library.remove_hooks()
import importme2
'''
code2 = '''
import socketserver
print('Uh oh. importme2 should have raised an ImportError.')
'''
self._write_test_script(code1, 'importme1.py')
self._write_test_script(code2, 'importme2.py')
with self.assertRaises(CalledProcessError):
output = self._run_test_script('importme1.py')
评论列表
文章目录