Skip to content

return values from generator decorator #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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