aiohttp stub throws away all recorded responses to the same endpoint except for the last one
See original GitHub issueHi,
we are using vcrpy to test our api client, built on aiohttp. When upgrading to the 2.1.0 release we noticed our tests started failing. In the failing test, we are making multiple calls to the same URL in succession. It seems that when playing back the casette, vcrpy throws away all but the last response.
I have created a minimal script to demonstrate the behavior. It seems to be specific to the aiohttp stub:
#! /usr/bin/env python3
import asyncio
import aiohttp
import vcr
@vcr.use_cassette("test_casette.yaml")
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('https://postman-echo.com/get') as resp:
print('FIRST RESPONSE:')
print(resp.headers)
async with session.get('https://postman-echo.com/get') as resp:
print('SECOND RESPONSE:')
print(resp.headers)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
When running the script twice in succession, we can observe the difference in output between the first run (with real requests) and the second (requests recorded by vcr):
(venv)[hugo@hugos-mbp vcr_demo]$ python demo.py
FIRST RESPONSE:
<CIMultiDictProxy('Content-Encoding': 'gzip', 'Content-Type': 'application/json; charset=utf-8', 'Date': 'Fri, 16 Aug 2019 10:47:11 GMT', 'Etag': 'W/"e4-Us7L+i6yExRm9KG9mNvMvSP9DQ8"', 'Server': 'nginx', 'Set-Cookie': 'sails.sid=s%3AI6gIdE3cbaI1pza-0CWg621ScWcCNBAV.b8XF%2FDL42icPhHSBA8Cdl50FV%2BthHFk5ztcMdxySJ5M; Path=/; HttpOnly', 'Vary': 'Accept-Encoding', 'Content-Length': '171', 'Connection': 'keep-alive')>
SECOND RESPONSE:
<CIMultiDictProxy('Content-Encoding': 'gzip', 'Content-Type': 'application/json; charset=utf-8', 'Date': 'Fri, 16 Aug 2019 10:47:11 GMT', 'Etag': 'W/"14e-BBSrIh8nOQJ4wopc8Pj851uldcU"', 'Server': 'nginx', 'Vary': 'Accept-Encoding', 'Content-Length': '271', 'Connection': 'keep-alive')>
(venv)[hugo@hugos-mbp vcr_demo]$ python demo.py
FIRST RESPONSE:
<CIMultiDictProxy('Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Content-Length': '271', 'Content-Type': 'application/json; charset=utf-8', 'Date': 'Fri, 16 Aug 2019 10:47:11 GMT', 'Etag': 'W/"14e-BBSrIh8nOQJ4wopc8Pj851uldcU"', 'Server': 'nginx', 'Vary': 'Accept-Encoding')>
SECOND RESPONSE:
None
The expected behavior is that both runs are identical, but when using the recording the second response is returned for the first request, and the second request returns nothing at all. It seems that first response is dropped entirely, although when examining the cassette file it is present.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Hey y’all. I finally found time and energy to resolving this issue via #495.
@HugoArts if you have time and are interested in seeing if my fork resolves your issue that would be awesome. No worries if not! There are test cases that should resemble the behavior we both identified.
Closing as fixed but please reopen if it hasn’t.