gh-123780: Make test_pkgutil clean up `spam` module (GH-123036)

This commit is contained in:
Malcolm Smith 2024-09-06 14:23:55 +01:00 committed by GitHub
parent 782a076362
commit eca3fe40c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 4 deletions

View File

@ -624,8 +624,11 @@ class ImportlibMigrationTests(unittest.TestCase):
mod = type(sys)(name)
del mod.__spec__
with CleanImport(name):
sys.modules[name] = mod
loader = pkgutil.get_loader(name)
try:
sys.modules[name] = mod
loader = pkgutil.get_loader(name)
finally:
sys.modules.pop(name, None)
self.assertIsNone(loader)
@ignore_warnings(category=DeprecationWarning)
@ -634,8 +637,11 @@ class ImportlibMigrationTests(unittest.TestCase):
mod = type(sys)(name)
mod.__spec__ = None
with CleanImport(name):
sys.modules[name] = mod
loader = pkgutil.get_loader(name)
try:
sys.modules[name] = mod
loader = pkgutil.get_loader(name)
finally:
sys.modules.pop(name, None)
self.assertIsNone(loader)
@ignore_warnings(category=DeprecationWarning)