From b1c45cd249ec6e6a6f68d439291070d09393bd53 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 23 Jan 2024 15:07:23 +0000 Subject: [PATCH 1/2] return values from generator decorator --- vcr/cassette.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcr/cassette.py b/vcr/cassette.py index fad0d25d..5a189e32 100644 --- a/vcr/cassette.py +++ b/vcr/cassette.py @@ -125,7 +125,7 @@ def _handle_generator(self, fn): duration of the generator. """ with self as cassette: - yield from fn(cassette) + return (yield from fn(cassette)) def _handle_function(self, fn): with self as cassette: From 6252b92f5051fda12038a666611503d7f23a765b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 23 Jan 2024 17:29:35 +0000 Subject: [PATCH 2/2] add test for generator decorator return --- tests/unit/test_vcr.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/test_vcr.py b/tests/unit/test_vcr.py index e285eb6d..9e4d4bf0 100644 --- a/tests/unit/test_vcr.py +++ b/tests/unit/test_vcr.py @@ -372,3 +372,19 @@ def test_path_class_as_cassette(): ) with use_cassette(path): pass + + +def test_use_cassette_generator_return(): + ret_val = object() + + vcr = VCR() + + @vcr.use_cassette("test") + def gen(): + return ret_val + yield + + with pytest.raises(StopIteration) as exc_info: + next(gen()) + + assert exc_info.value.value is ret_val