Skip to content

Multiple responses per endpoint #302

Open
@hynek

Description

@hynek

Hi, thanks for the great project! There's one thing that keeps tripping me up and that's when I want to return multiple responses after each request. For example, to exercise retries.

Currently I'm using the following pattern:

        resps = [...]

        def respond(req):
            return resps.pop(0)

        httpserver.expect_request("/").respond_with_handler(
            respond
        )

Which can be generalized to:

@attrs.define
class MultipleResponsesHandler:
    _responses: list[Response]

    def __call__(self, _):
        return self._responses.pop(0)

httpserver.expect_request("/").respond_with_handler(
    MultipleResponsesHandler(...)
)

Is there a more elegant way to achieve this and/or should this be part of pytest-httpserver?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions