Skip to content

Commit

Permalink
Merge pull request #811 from kevin1024/graingert-patch-1
Browse files Browse the repository at this point in the history
return values from generator decorator
  • Loading branch information
graingert authored Jan 24, 2024
2 parents 1e3a5ac + 6252b92 commit f76289a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/unit/test_vcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion vcr/cassette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f76289a

Please sign in to comment.