pydantic / pydantic/httpx2

MockTransport doesn't set the elapsed property

Open
#914 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
78
Avg merge
8h 59m
Merged PRs (30d)
24

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating MockTransport and the Response elapsed property in the repository, then inspect how manually created responses are handled. Compare the three proposed behaviors and existing transport tests; done means an agreed behavior is implemented and covered by tests without requiring handler boilerplate.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.