mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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.
This commit is contained in:
parent
7f4ae1b2cc
commit
3cf7ea1272
1 changed files with 4 additions and 4 deletions
|
@ -2250,7 +2250,8 @@ class OriginTrackingTest(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
warnings._warn_unawaited_coroutine = lambda coro: 1/0
|
warnings._warn_unawaited_coroutine = lambda coro: 1/0
|
||||||
with support.catch_unraisable_exception() as cm, \
|
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
|
# only store repr() to avoid keeping the coroutine alive
|
||||||
coro = corofn()
|
coro = corofn()
|
||||||
coro_repr = repr(coro)
|
coro_repr = repr(coro)
|
||||||
|
@ -2261,13 +2262,12 @@ class OriginTrackingTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(repr(cm.unraisable.object), coro_repr)
|
self.assertEqual(repr(cm.unraisable.object), coro_repr)
|
||||||
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
|
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
|
||||||
self.assertIn("was never awaited", stream.getvalue())
|
|
||||||
|
|
||||||
del warnings._warn_unawaited_coroutine
|
del warnings._warn_unawaited_coroutine
|
||||||
with support.captured_stderr() as stream:
|
with support.check_warnings((r'coroutine .* was never awaited',
|
||||||
|
RuntimeWarning)):
|
||||||
corofn()
|
corofn()
|
||||||
support.gc_collect()
|
support.gc_collect()
|
||||||
self.assertIn("was never awaited", stream.getvalue())
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
warnings._warn_unawaited_coroutine = orig_wuc
|
warnings._warn_unawaited_coroutine = orig_wuc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue