本文整理汇总了Python中test.support.modules_cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python support.modules_cleanup方法的具体用法?Python support.modules_cleanup怎么用?Python support.modules_cleanup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.support
的用法示例。
在下文中一共展示了support.modules_cleanup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modules_cleanup
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import modules_cleanup [as 别名]
def modules_cleanup(oldmodules):
# Encoders/decoders are registered permanently within the internal
# codec cache. If we destroy the corresponding modules their
# globals will be set to None which will trip up the cached functions.
encodings = [(k, v) for k, v in sys.modules.items()
if k.startswith('encodings.')]
sys.modules.clear()
sys.modules.update(encodings)
# XXX: This kind of problem can affect more than just encodings. In
# particular extension modules (such as _ssl) don't cope with reloading
# properly. Really, test modules should be cleaning out the test
# specific modules they know they added (ala test_runpy) rather than
# relying on this function (as test_importhooks and test_pkg do
# currently). Implicitly imported *real* modules should be left alone
# (see issue 10556).
sys.modules.update(oldmodules)
示例2: setUp
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import modules_cleanup [as 别名]
def setUp(self):
modules = modules_setup()
self.addCleanup(modules_cleanup, *modules)
示例3: tearDown
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import modules_cleanup [as 别名]
def tearDown(self):
sys.path[:] = self.syspath
support.modules_cleanup(*self.modules_before)
if self.root: # Only clean if the test was actually run
cleanout(self.root)
# delete all modules concerning the tested hierarchy
if self.pkgname:
modules = [name for name in sys.modules
if self.pkgname in name.split('.')]
for name in modules:
del sys.modules[name]
示例4: tearDown
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import modules_cleanup [as 别名]
def tearDown(self):
sys.path[:] = self.path
sys.meta_path[:] = self.meta_path
sys.path_hooks[:] = self.path_hooks
sys.path_importer_cache.clear()
support.modules_cleanup(*self.modules_before)
示例5: test_sundry
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import modules_cleanup [as 别名]
def test_sundry(self):
old_modules = support.modules_setup()
try:
for fn in os.listdir(scriptsdir):
if not fn.endswith('.py'):
continue
name = fn[:-3]
if name in self.skiplist:
continue
import_tool(name)
finally:
# Unload all modules loaded in this test
support.modules_cleanup(*old_modules)