Simplify testing the warning filename (GH-91868)

The context manager result has the "filename" attribute.
This commit is contained in:
Serhiy Storchaka 2022-04-24 10:23:59 +03:00 committed by GitHub
parent b4e048411f
commit 090721721b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 43 deletions

View file

@ -2608,11 +2608,11 @@ class ImplementationTest(unittest.TestCase):
for name in deprecated:
with self.subTest(module=name):
sys.modules.pop(name, None)
with self.assertWarns(DeprecationWarning) as cm:
with self.assertWarns(DeprecationWarning) as w:
__import__(name)
self.assertEqual(str(cm.warnings[0].message),
self.assertEqual(str(w.warning),
f"module {name!r} is deprecated")
self.assertEqual(cm.warnings[0].filename, __file__)
self.assertEqual(w.filename, __file__)
self.assertIn(name, sys.modules)
mod = sys.modules[name]
self.assertEqual(mod.__name__, name)