Skip to content

MockTransport doesn't set the elapsed property #914

@Kludex

Description

@Kludex

Originally opened by @ionelmc on 2025-11-24 20:54:00 in encode/httpx

This is not a nice solution:

def handler(request):
    resp = httpx.Response(200, json={"text": "Hello, world!"})
    resp.elapsed = timedelta(.......
    return resp

If you have dispatch code in that handler that can easily get boilerplatey.

I think httpx should do either of these:

  • MockTransport take the duration as an optional argument
  • httpx provide a decorator, so you can wrap your handler in it
  • automatically set a duration of 0 for manually created Response objects - why error out if the data is already there?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions