vcrpy
vcrpy copied to clipboard
fix: usage of io-like interface with VCR.py
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