[3.13] gh-123780: Make test_pkgutil clean up `spam` module (GH-123036) (#123781)

gh-123780: Make test_pkgutil clean up `spam` module (GH-123036)
(cherry picked from commit eca3fe40c2)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
This commit is contained in:
Miss Islington (bot) 2024-09-06 22:57:46 +02:00 committed by GitHub
parent e62cb77c25
commit 72cdd2ade6
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)