Skip to content

Add support for httpx2 - #239

Open
Klavionik wants to merge 2 commits into
Colin-b:developfrom
Klavionik:add_httpx2_support
Open

Add support for httpx2#239
Klavionik wants to merge 2 commits into
Colin-b:developfrom
Klavionik:add_httpx2_support

Conversation

@Klavionik

Copy link
Copy Markdown

Hey! I'm trying to add support for the httpx2 package, following the guidelines from the authors.

This PR allows users of the package to seamlessly migrate their application and test code from httpx, just by updating the package. Users who have no intentions to migrate will be fine as well: the added _compat.py module tries to use httpx2 first, but falls back to httpx.

This is a highly anticipated change I assume, so I'm looking forward for a review and any comments/suggestions are very welcome.

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

Comment thread pyproject.toml
]
dependencies = [
"httpx==0.28.*",
"httpx2==2.*",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it's worth doing this as an extra?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather remove both httpx and httpx2 as dependencies. Make them optional (as the suggestion above, an extra dependency for each)

Comment thread pytest_httpx/_compat.py
Comment on lines +22 to +24
"pytest-httpx requires the httpx2 package to be installed.\n"
"You can install it with:\n"
" $ pip install httpx2\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this choice up to the user and not talk about the need, because migration does not happen so quickly.

"Neither `httpx2` nor the legacy `httpx` package is installed.\n"
"Install `httpx2` with:\n"
"    $ pip install httpx2\n"

@bagowix

bagowix commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@Colin-b Hi! Could we prioritize this, if possible, please?

@Klavionik

Copy link
Copy Markdown
Author

@Colin-b Kind reminder. 🙏🏻

@Colin-b Colin-b left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it needs more work, I envision the following in term of support:

  1. only httpx2 installed -> valid
  2. only httpx installed -> valid
  3. both installed -> use httpx2

This would need to be documented, and ofc the test suite will need to be updated, same for the CI that will need to run in 3 different dependency setup.

I am however not asking you to do it, I can review this proposal a bit more and add those changes.

@Klavionik

Copy link
Copy Markdown
Author

I could work on these changes if it helps.

So, the plan would be:

  1. Turn httpx and httpx2 into extra dependencies. pip install pytest-httpx will then install just this package.
  2. Update the docs to explain the new ways to install pytest-httpx.
  3. Update the test suite and the CI config to run in three environments: only httpx, only httpx2, httpx + httpx2. Perhaps add a test case to cover the compatibility layer itself?

Is that correct?

I envision the following in term of support:
...

I believe it works exactly this way right now.

@Colin-b

Colin-b commented Aug 31, 2026

Copy link
Copy Markdown
Owner

If you feel like it, be my guest!
Note that I made a mistake in my suggestion when both are installed, and I think it makes it slightly less straightforward to handle.
When both dependencies are installed, we should mock both, I did not put thoughts into the actual implementation but I would like to avoid as much code duplication as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants