As discussed in #271, it's quite annoying that StopIteration is raised when an iterable side effect is exhausted.
In most cases, it's probably more reasonable to have the last entry repeated, which the docs has been adjusted (#287).
Since current behaviour is by design, to align with pythons already familiar built-in unittest Mock behaviour, we should find a way to opt-in for the new logic, e.g. by ..
.. providing a repeat_last utility to shortcut chain + repeat ..
respx.get("https://example.org/").mock(
side_effect=repeat_last(
httpx.Response(201),
httpx.Response(200),
)
)
.. or alter the api by adding an optional kwarg to route.mock(..) ..
respx.get("https://example.org/").mock(
side_effect=[
httpx.Response(201),
httpx.Response(200),
],
repeat_last=True,
)
I'm leaning towards the utility shortcut, as a first step.
As discussed in #271, it's quite annoying that
StopIterationis raised when an iterable side effect is exhausted.In most cases, it's probably more reasonable to have the last entry repeated, which the docs has been adjusted (#287).
Since current behaviour is by design, to align with pythons already familiar built-in unittest
Mockbehaviour, we should find a way to opt-in for the new logic, e.g. by .... providing a
repeat_lastutility to shortcut chain + repeat .... or alter the api by adding an optional kwarg to
route.mock(..)..I'm leaning towards the utility shortcut, as a first step.