kevin1024 / vcrpy

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

async httpx streaming doesn't work #597

Open AGhost-7 opened 3 years ago

AGhost-7 commented 3 years ago

Steps to reproduce:

  1. Use vcrpy with async httpx along with chunked http. E.g.:
    
    with vcr.use_cassette("sample.yml"):
        async with client.stream(
                "POST",
                "/sample-path"
                },
            ) as response:
              async for chunk in response.aiter_lines():
                print('chunk', chunk)


Expected behaviour: it successfully records / replays content.

Actual behaviour: I get an exception: `vcr/stubs/httpx_stubs.py:72: IndexError`. httpx's `stream` method calls `send` with no args (only kwargs).
kukovecz commented 2 years ago

Same issue with the sync version, with the latest release (v4.2.1).

Sample code to reproduce:

with httpx.stream("GET", "<URL>") as response:
    for chunk in response.iter_bytes():
        print(chunk)

Error:

cassette = <vcr.cassette.Cassette object at 0x7f3430d1aa10>, real_send = <function Client.send at 0x7f34369e7d90>, args = (<httpx.Client object at 0x7f3430d2dba0>,)
kwargs = {'auth': None, 'follow_redirects': False, 'request': <Request('GET', '<URL>')>, 'stream': True}

    def _shared_vcr_send(cassette, real_send, *args, **kwargs):
>       real_request = args[1]
E       IndexError: tuple index out of range

.venv/lib/python3.10/site-packages/vcr/stubs/httpx_stubs.py:79: IndexError

This works fine with get instead of stream:

response = httpx.get("<URL>")
for chunk in response.iter_bytes():
    print(chunk)
parkerhancock commented 12 months ago

I suggest we close this one in view of #784