Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance iterable side effect experience #288

Open
lundberg opened this issue Jan 20, 2025 · 0 comments
Open

Enhance iterable side effect experience #288

lundberg opened this issue Jan 20, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@lundberg
Copy link
Owner

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.

@lundberg lundberg added the enhancement New feature or request label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant