MCPcopy Index your code
hub / github.com/python/cpython / check_import_fresh_module

Method check_import_fresh_module

Lib/test/test_capi/test_import.py:41–53  ·  view source on GitHub ↗
(self, import_module)

Source from the content-addressed store, hash-verified

39 self.assertIs(module, old_module)
40
41 def check_import_fresh_module(self, import_module):
42 old_modules = dict(sys.modules)
43 try:
44 for name in ('colorsys', 'math'):
45 with self.subTest(name=name):
46 sys.modules.pop(name, None)
47 module = import_module(name)
48 self.assertIsInstance(module, types.ModuleType)
49 self.assertIs(module, sys.modules[name])
50 self.assertEqual(module.__name__, name)
51 finally:
52 sys.modules.clear()
53 sys.modules.update(old_modules)
54
55 def test_getmodule(self):
56 # Test PyImport_GetModule()

Callers 1

check_import_funcMethod · 0.95

Calls 8

assertIsInstanceMethod · 0.80
import_moduleFunction · 0.50
subTestMethod · 0.45
popMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected