diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2018-01-21 14:44:07 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-01-21 14:44:07 (GMT) |
commit | fc2f407829d9817ddacccae6944dd0879cfaca24 (patch) | |
tree | 1775a28a8181975363798f9b3e7cb2bb100e49a2 /Lib/test/test_asyncio/test_pep492.py | |
parent | 1211c9a9897a174b7261ca258cabf289815a40d8 (diff) | |
download | cpython-fc2f407829d9817ddacccae6944dd0879cfaca24.zip cpython-fc2f407829d9817ddacccae6944dd0879cfaca24.tar.gz cpython-fc2f407829d9817ddacccae6944dd0879cfaca24.tar.bz2 |
bpo-32591: Add native coroutine origin tracking (#5250)
* Add coro.cr_origin and sys.set_coroutine_origin_tracking_depth
* Use coroutine origin information in the unawaited coroutine warning
* Stop using set_coroutine_wrapper in asyncio debug mode
* In BaseEventLoop.set_debug, enable debugging in the correct thread
Diffstat (limited to 'Lib/test/test_asyncio/test_pep492.py')
-rw-r--r-- | Lib/test/test_asyncio/test_pep492.py | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py index 289f7e5..f2d588f 100644 --- a/Lib/test/test_asyncio/test_pep492.py +++ b/Lib/test/test_asyncio/test_pep492.py @@ -1,5 +1,6 @@ """Tests support for new syntax introduced by PEP 492.""" +import sys import types import unittest @@ -148,35 +149,14 @@ class CoroutineTests(BaseTest): data = self.loop.run_until_complete(foo()) self.assertEqual(data, 'spam') - @mock.patch('asyncio.coroutines.logger') - def test_async_def_wrapped(self, m_log): - async def foo(): - pass + def test_debug_mode_manages_coroutine_origin_tracking(self): async def start(): - foo_coro = foo() - self.assertRegex( - repr(foo_coro), - r'<CoroWrapper .*\.foo\(\) running at .*pep492.*>') - - with support.check_warnings((r'.*foo.*was never', - RuntimeWarning)): - foo_coro = None - support.gc_collect() - self.assertTrue(m_log.error.called) - message = m_log.error.call_args[0][0] - self.assertRegex(message, - r'CoroWrapper.*foo.*was never') + self.assertTrue(sys.get_coroutine_origin_tracking_depth() > 0) + self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0) self.loop.set_debug(True) self.loop.run_until_complete(start()) - - async def start(): - foo_coro = foo() - task = asyncio.ensure_future(foo_coro, loop=self.loop) - self.assertRegex(repr(task), r'Task.*foo.*running') - - self.loop.run_until_complete(start()) - + self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0) def test_types_coroutine(self): def gen(): @@ -226,9 +206,9 @@ class CoroutineTests(BaseTest): t.cancel() self.loop.set_debug(True) - with self.assertRaisesRegex( - RuntimeError, - r'Cannot await.*test_double_await.*\bafunc\b.*while.*\bsleep\b'): + with self.assertRaises( + RuntimeError, + msg='coroutine is being awaited already'): self.loop.run_until_complete(runner()) |