def test_importlib_import_relative_pkg(self):
"""Verify that package is importable relatively"""
print_importers()
assert __package__
# need globals to handle relative imports
# __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__ + '.pkg'):
raise unittest.SkipTest("module previously loaded".format(__package__ + '.pkg'))
else:
pkg = importlib.__import__('pkg', globals=globals(), level=1)
test_pkg = pkg
self.assertTrue(test_pkg is not None)
self.assertTrue(test_pkg.TestClassInSubPkg is not None)
self.assertTrue(callable(test_pkg.TestClassInSubPkg))
# TODO : implement some differences and check we get them...
if hasattr(importlib, 'reload'): # recent version of importlib
# attempting to reload
importlib.reload(test_pkg)
else:
pass
test_filefinder2_importlib_import.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录