question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aiohttp stub throws away all recorded responses to the same endpoint except for the last one

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdirienzocommented, Dec 1, 2019

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.

0reactions
neozenithcommented, Dec 14, 2019

Closing as fixed but please reopen if it hasn’t.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Differences between requests and aiohttp cassettes · Issue #463
My open-source library supports sync and async at the same time, ... aiohttp stub throws away all recorded responses to the same endpoint...
Read more >
Server Reference — aiohttp 3.8.3 documentation
Originating IP address of a client initiated HTTP request. The IP is resolved through the following headers, in this order: Overridden value by...
Read more >
How can I mock requests and the response? - python
I am trying to generalise it for POST and PUT but cannot understand, how I can supply extra data to be used inside...
Read more >
pytest Documentation - Read the Docs
The first test passed and the second failed. You can easily see the intermediate values in the assertion to help you under-.
Read more >
Implementing Interfaces to Transport Services draft-ietf-taps ...
For example, the same Connection object may ultimately represent a single ... application specifies one or more Endpoints to be used for communication...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found