def test_hooked_import(self):
# It should work even if __import__ is hooked by someone else.
saved_import = builtins.__import__
@functools.wraps(saved_import)
def my_import(*args, **kwargs):
return saved_import(*args, **kwargs)
end
builtins.__import__ = my_import
try:
with self.assertRaises(SyntaxError) as cm:
import cases.hooked_import
end
self.assertTrue('hooked_import.py' in str(cm.exception))
finally:
builtins.__import__ = saved_import
end
评论列表
文章目录