From 6d7a842a333ac641300ec7cc384424178e72db56 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 23 Jan 2024 12:14:58 +0000 Subject: [PATCH] fix test_tornado_exception_can_be_caught RuntimeError: generator raised StopIteration --- vcr/cassette.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/vcr/cassette.py b/vcr/cassette.py index 1b8b1f2..fad0d25 100644 --- a/vcr/cassette.py +++ b/vcr/cassette.py @@ -3,7 +3,6 @@ import contextlib import copy import inspect import logging -import sys from asyncio import iscoroutinefunction import wrapt @@ -126,20 +125,7 @@ class CassetteContextDecorator: duration of the generator. """ with self as cassette: - coroutine = fn(cassette) - # We don't need to catch StopIteration. The caller (Tornado's - # gen.coroutine, for example) will handle that. - to_yield = next(coroutine) - while True: - try: - to_send = yield to_yield - except Exception: - to_yield = coroutine.throw(*sys.exc_info()) - else: - try: - to_yield = coroutine.send(to_send) - except StopIteration: - break + yield from fn(cassette) def _handle_function(self, fn): with self as cassette: