kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing
MIT License
2.69k stars 387 forks source link

httpx cassettes not compatible with vcr format #550

Open geraxe opened 4 years ago

geraxe commented 4 years ago

httpx not worked from box if we create simple test

import pytest
import httpx

@pytest.mark.vcr()
def test_iana():
    response = httpx.get('http://www.iana.org/domains/reserved')
    assert b'Example domains' in response.content

and run it pytest --record-mode=once tests/test_vcr.py

we have error with cassette file format

>           new_body = decompress_body(response["body"]["string"], encoding)
E           KeyError: 'body'

vcr/filters.py:158: KeyError

because cassette file format for httpx uses content parameter, but all other stubs use body.string parameters to save and filter result

and if we will use existing cassettes with httpx it won`t work for the same reason

geraxe commented 3 years ago

591

finswimmer commented 1 year ago

Hey,

interesting that this issue is open for so long. We are replacing requests by httpx in more and more projects. So it would be great to get this issue fixed :smiley:

Thanks a lot for this great project :+1: