Open dmfigol opened 5 years ago
Please feel free to submit a PR on this matter, it's definitely relevant to have identical cassettes whatever library we use to do a request.
Hi, thanks for raising this issue! It makes sense that the cassettes should be consistent.
If you don't have the bandwidth to open a PR. Linking to a toy repo that replicates the issue helps a lot if others want to pick up this issue and contribute the fix/enhancement.
I was poking around and saw the release milestones (thanks for putting them, such up @neozenith!). This is in-scope for the 2.2.x release (https://github.com/kevin1024/vcrpy/milestone/3).
I opened up an example cassette of how the two compare more specifically (after some modifications to how aiohttp's stub works).
I'm in favor of sharing cassettes across clients; it makes sense for library development where you want HTTP request parity across sync and async implementations. There are some other specific differences to figure out how to handle, such as:
requests
adds an implicit /
to root URLsrequests
adds default headers like User-Agent: python-requests/2.22.0
which may have issues with default matchingHow should we handle these two cases?
Hmmm... maybe I was overthinking that. According to test runs, I'm able to share a requests
cassette with aiohttp
after some changes with how headers are handled on specific endpoints. The root path is still finicky with matching, it seems.
Perhaps https://github.com/nickdirienzo/vcrpy/pull/1 is on to something?
If someone wants to share cassettes between requests and aiohttp, should they ensure the encoding is handled correctly between the two, or should that be on vcrpy? I feel like it should be on the implementer because that complicates what the stubs are doing and makes them more aware of other clients, but I imagine there are reasons to not want that.
Thank you for the library. My open-source library supports sync and async at the same time, so I'd love to use the same cassette for both tests. However, there are some challenges. Here are the cassettes fragments for requests and aiohttp:
requests
:aiohttp
:We can see two main differences:
1) in
requests
cassette response headers are serialized askey -> list of strings
, inaiohttp
cassette they are serialized askey -> str
2) inaiohttp
cassette there is a response url key which equals to the request url,requests
cassette does not have thatAlso, because of 2),
requests
cassette played inaiohttp
code will crash: