def test_importlib_import_class_from_relative_ns_subpkg(self):
"""Verify that message class is importable relatively"""
print_importers()
assert __package__
# __import__ checks sys.modules by itself
# but the test is not reflecting anything if we use the already loaded module.
if sys.modules.get(__package__ + '.nspkg.subpkg'):
raise unittest.SkipTest("module previously loaded".format(__package__ + '.nspkg.subpkg'))
else:
nspkg = importlib.__import__('nspkg.subpkg', globals=globals(),
level=1) # need globals to handle relative imports
test_class_in_subpkg = nspkg.subpkg.TestClassInSubPkg
self.assertTrue(test_class_in_subpkg is not None)
self.assertTrue(callable(test_class_in_subpkg))
# TODO : implement some differences and check we get them...
if hasattr(importlib, 'reload'): # recent version of importlib
# attempting to reload
importlib.reload(nspkg)
else:
pass
test_filefinder2_importlib_import.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录