@@ -113,6 +113,12 @@ def setUp(self):
113
113
self .loader = self .machinery .ExtensionFileLoader (
114
114
self .name , self .spec .origin )
115
115
116
+ def tearDown (self ):
117
+ try :
118
+ del sys .modules [self .name ]
119
+ except KeyError :
120
+ pass
121
+
116
122
def load_module (self ):
117
123
with warnings .catch_warnings ():
118
124
warnings .simplefilter ("ignore" , DeprecationWarning )
@@ -194,6 +200,12 @@ def setUp(self):
194
200
self .loader = self .machinery .ExtensionFileLoader (
195
201
self .name , self .spec .origin )
196
202
203
+ def tearDown (self ):
204
+ try :
205
+ del sys .modules [self .name ]
206
+ except KeyError :
207
+ pass
208
+
197
209
def load_module (self ):
198
210
# Load the module from the test extension.
199
211
with warnings .catch_warnings ():
@@ -262,15 +274,16 @@ def test_reload(self):
262
274
263
275
def test_try_registration (self ):
264
276
# 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 )
274
287
275
288
def test_load_submodule (self ):
276
289
# Test loading a simulated submodule.
0 commit comments