[3.13] gh-71339: Use new assertion methods in test_import and test_importlib (GH-129052) (#129123)

(cherry picked from commit f7cc7d296c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Serhiy Storchaka 2025-04-08 13:43:04 +03:00 committed by GitHub
parent d2ec87f740
commit a9bb0092d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 68 additions and 64 deletions

View file

@ -430,8 +430,7 @@ def test_everyone_has___loader__(self):
for name, module in sys.modules.items():
if isinstance(module, types.ModuleType):
with self.subTest(name=name):
self.assertTrue(hasattr(module, '__loader__'),
'{!r} lacks a __loader__ attribute'.format(name))
self.assertHasAttr(module, '__loader__')
if self.machinery.BuiltinImporter.find_spec(name):
self.assertIsNot(module.__loader__, None)
elif self.machinery.FrozenImporter.find_spec(name):
@ -441,7 +440,7 @@ def test_everyone_has___spec__(self):
for name, module in sys.modules.items():
if isinstance(module, types.ModuleType):
with self.subTest(name=name):
self.assertTrue(hasattr(module, '__spec__'))
self.assertHasAttr(module, '__spec__')
if self.machinery.BuiltinImporter.find_spec(name):
self.assertIsNot(module.__spec__, None)
elif self.machinery.FrozenImporter.find_spec(name):