8000 add `tearDown` and clear module cache · python/cpython@ae45649 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae45649

Browse files
committed
add tearDown and clear module cache
1 parent 1630345 commit ae45649

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Lib/test/test_importlib/extension/test_loader.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def setUp(self):
113113
self.loader = self.machinery.ExtensionFileLoader(
114114
self.name, self.spec.origin)
115115

116+
def tearDown(self):
117+
try:
118+
del sys.modules[self.name]
119+
except KeyError:
120+
pass
121+
116122
def load_module(self):
117123
with warnings.catch_warnings():
118124
warnings.simplefilter("ignore", DeprecationWarning)
@@ -194,6 +200,12 @@ def setUp(self):
194200
self.loader = self.machinery.ExtensionFileLoader(
195201
self.name, self.spec.origin)
196202

203+
def tearDown(self):
204+
try:
205+
del sys.modules[self.name]
206+
except KeyError:
207+
pass
208+
197209
def load_module(self):
198210
# Load the module from the test extension.
199211
with warnings.catch_warnings():
@@ -262,15 +274,16 @@ def test_reload(self):
262274

263275
def test_try_registration(self):
264276
# Assert that the PyState_{Find,Add,Remove}Module C API doesn't work.
265-
module = self.load_module()
266-
with self.subTest('PyState_FindModule'):
267-
self.assertEqual(module.call_state_registration_func(0), None)
268-
with self.subTest('PyState_AddModule'):
269-
with self.assertRaises(SystemError):
270-
module.call_state_registration_func(1)
271-
with self.subTest('PyState_RemoveModule'):
272-
with self.assertRaises(SystemError):
273-
module.call_state_registration_func(2)
277+
with util.uncache(self.name):
278+
module = 7888 self.load_module()
279+
with self.subTest('PyState_FindModule'):
280+
self.assertEqual(module.call_state_registration_func(0), None)
281+
with self.subTest('PyState_AddModule'):
282+
with self.assertRaises(SystemError):
283+
module.call_state_registration_func(1)
284+
with self.subTest('PyState_RemoveModule'):
285+
with self.assertRaises(SystemError):
286+
module.call_state_registration_func(2)
274287

275288
def test_load_submodule(self):
276289
# Test loading a simulated submodule.

0 commit comments

Comments
 (0)
0