diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 712f9cde3a7..72fcc736610 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -104,7 +104,15 @@ class FilterTests(BaseTest): message = "FilterTests.test_ignore_after_default" def f(): self.module.warn(message, UserWarning) - f() + + with support.captured_stderr() as stderr: + f() + stderr = stderr.getvalue() + self.assertIn("UserWarning: FilterTests.test_ignore_after_default", + stderr) + self.assertIn("self.module.warn(message, UserWarning)", + stderr) + self.module.filterwarnings("error", category=UserWarning) self.assertRaises(UserWarning, f)