Skip to content
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

fix: usage of io-like interface with VCR.py #906

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tito
Copy link

@tito tito commented Jan 22, 2025

This pull request aims to resolve an issue with using VCR.py in conjunction with io-like data.
Let's have a look at this example:

@vcr.use_cassette("issue_vcr_aiohttp.yaml")
def test():
    test = io.BytesIO(b"hello")
    async with aiohttp.ClientSession() as session:
        async with session.post("https://httpbin.org/post", data=test, json=None) as response:
            ret = await response.json()
            assert ret["data"] == "hello"

It will trigger the assert, because the body received by aiohttp will be empty.
When using cassette and building Request, the body is read() and later usage of body by aiohttp won't work.

Fix provided with the help of @kevdevg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants