From 0025eb145fb4e66c9faad696a0e1033d0a1c3375 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 26 May 2016 15:21:25 +0200 Subject: [PATCH] test_warnings: catch stderr and check warning Check the user warning in test_error_after_default() to not pollute the output, and check the warning logged into stderr. --- Lib/test/test_warnings/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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)