pytest-vcr
pytest-vcr copied to clipboard
Doesn't work with httpx
I'm not sure whether this package is expected to work with httpx but I'm getting the following error when recording a new cassette with decode_compressed_response=True:
> new_body = decompress_body(response["body"]["string"], encoding)
E KeyError: 'body'
Monkey patch:
from vcr.stubs import httpx_stubs
def _transform_headers(httpx_response):
out = {}
for key, var in httpx_response.headers.raw:
decoded_key = key.decode('utf-8')
decoded_var = var.decode('utf-8')
if decoded_key.lower() == 'content-encoding' and decoded_var in ('gzip', 'deflate'):
continue
out.setdefault(decoded_key, [])
out[decoded_key].append(decoded_var)
return out
httpx_stubs._transform_headers = _transform_headers
See: https://github.com/kevin1024/vcrpy/pull/591 and https://github.com/kevin1024/vcrpy/pull/649