Open jborman-stonex opened 6 months ago
This is not a bug, and instead by design to align with how pythons existing unittest Mock
behave.
Though, I can kind-of agree with you that it would be a nicer experience if it would work like you suggest, but I think it's better and cleaner if it works like the already familiar mock api.
To get your desired outcome, you could utilize itertools
, e.g.
from itertools import chain, repeat
respx.post("https://example.org/").mock(
side_effect=chain(
[httpx.Response(201)],
repeat(httpx.Response(200)),
),
)
Environment
Using the latest
respx==0.21.1
withpytest==8.0.0
andpytest-mock==3.12.0
Issue
Following the
respx
docs for mocking a response using both aside_effect
andreturn_value
raises aStopIteration
error.While the docs state the following as an example, the test does not actually pass.
Running the above via pytest I see:
Expectation
I would expect
respx
to catch thisStopIteration
error when areturn_value
is specified and return that value instead of propagating the error.