Issue 24342: Let wrapper set by sys.set_coroutine_wrapper fail gracefully

This commit is contained in:
Yury Selivanov 2015-06-02 18:43:51 -04:00
parent 231d90609b
commit aab3c4a211
6 changed files with 68 additions and 10 deletions

View file

@ -995,6 +995,26 @@ class SysSetCoroWrapperTest(unittest.TestCase):
sys.set_coroutine_wrapper(1)
self.assertIsNone(sys.get_coroutine_wrapper())
def test_set_wrapper_3(self):
async def foo():
return 'spam'
def wrapper(coro):
async def wrap(coro):
return await coro
return wrap(coro)
sys.set_coroutine_wrapper(wrapper)
try:
with self.assertRaisesRegex(
RuntimeError,
"coroutine wrapper.*\.wrapper at 0x.*attempted to "
"recursively wrap <coroutine.*\.wrap"):
foo()
finally:
sys.set_coroutine_wrapper(None)
class CAPITest(unittest.TestCase):