respx icon indicating copy to clipboard operation
respx copied to clipboard

Consider adding a MockStream

Open lundberg opened this issue 4 years ago • 2 comments

It might be of use if RESPX had a MockStream utility that could be passed as stream when creating a httpx.Response.

The MockStream should suport both sync and async contexts.

Ideas...

stream = MockStream(json={})
stream = MockStream(text="hello")

Also, mocking a response stream with content from local file would be of interest in some cases, e.g. large test responses. It should probably take either a file-path string or a file-like object.

stream = MockStream(file=...)

Other things to consider is form data and multipart responses.

lundberg avatar Jul 08 '21 14:07 lundberg

I have a difficulty try to mock stream response for a endpoint for both sync and async calls, because they expects different stream types, and side effect handler don't have enough context for figure out.

yihuang avatar Mar 24 '25 12:03 yihuang

I have a difficulty try to mock stream response for a endpoint for both sync and async calls, because they expects different stream types, and side effect handler don't have enough context for figure out.

@yihuang Before we consider #296 to "resolve" this issue, let's re-evaluate the possibility of a MockStream that suite both sync and async contexts.

Haven't looked, but I have a feeling it should be possible to just let one model just implement both "apis" 🤔

lundberg avatar Sep 15 '25 08:09 lundberg