Skip to content

Commit

Permalink
test_warnings: catch stderr and check warning
Browse files Browse the repository at this point in the history
Check the user warning in test_error_after_default() to not pollute the output,
and check the warning logged into stderr.
  • Loading branch information
vstinner committed May 26, 2016
1 parent 43593a1 commit 0025eb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ def test_error_after_default(self):
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)

Expand Down

0 comments on commit 0025eb1

Please sign in to comment.