Skip to content

MockTransport doesn't set the elapsed property #3712

@ionelmc

Description

@ionelmc

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions