[Python-checkins] bpo-37100: Fix test_coroutines with -Werror (GH-13756)

Victor Stinner webhook-mailer at python.org
Sun Jun 2 19:35:40 EDT 2019


https://github.com/python/cpython/commit/3cf7ea1272fbc921a89acdbe40ca152813028cb5
commit: 3cf7ea1272fbc921a89acdbe40ca152813028cb5
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-06-03T01:35:37+02:00
summary:

bpo-37100: Fix test_coroutines with -Werror (GH-13756)

test_coroutines: test_unawaited_warning_when_module_broken() now uses
support.check_warnings() to catch expected RuntimeWarning.

files:
M Lib/test/test_coroutines.py

diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 0e7eb3a1af47..b406b1c3ebf8 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -2250,7 +2250,8 @@ def test_unawaited_warning_when_module_broken(self):
         try:
             warnings._warn_unawaited_coroutine = lambda coro: 1/0
             with support.catch_unraisable_exception() as cm, \
-                 support.captured_stderr() as stream:
+                 support.check_warnings((r'coroutine .* was never awaited',
+                                         RuntimeWarning)):
                 # only store repr() to avoid keeping the coroutine alive
                 coro = corofn()
                 coro_repr = repr(coro)
@@ -2261,13 +2262,12 @@ def test_unawaited_warning_when_module_broken(self):
 
                 self.assertEqual(repr(cm.unraisable.object), coro_repr)
                 self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
-                self.assertIn("was never awaited", stream.getvalue())
 
             del warnings._warn_unawaited_coroutine
-            with support.captured_stderr() as stream:
+            with support.check_warnings((r'coroutine .* was never awaited',
+                                         RuntimeWarning)):
                 corofn()
                 support.gc_collect()
-            self.assertIn("was never awaited", stream.getvalue())
 
         finally:
             warnings._warn_unawaited_coroutine = orig_wuc



More information about the Python-checkins mailing list