-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTTPX support #91
Conversation
c201559
to
a1b2a56
Compare
Thanks @sarayourfriend! I've tried #91 and run into an error when trying to use @pook.on
@pytest.mark.asyncio
async def test_pook():
pass errors with
This doesn't happen with pook 1.1.1 |
Thanks @tekumara! I need to rebase this branch, I believe it would fix the issue with the coroutine issue you're seeing. The problem was that the wrapped async function in Here is the code that was fixed: pook/src/pook/activate_async.py Lines 18 to 26 in 16ecba6
Previously the Lines 17 to 26 in 3f2b818
|
a1b2a56
to
5b27419
Compare
5b27419
to
9e848ad
Compare
Update: I've rebased the branch since the changes in master and that should fix the issue you mentioned with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sarayourfriend I can confirm it now works well on my code base!
Awesome, thanks 🙏 I'm very excited to add httpx support in the next release 🎉 |
Thanks for adding this feature! PS: I like pook over alternatives because the no match error message shows any unmatched mocks which is great for debugging. |
Closes #71.
HTTPX documentation is here: https://www.python-httpx.org/
The current implementation supports everything, except HTTP2.
At first, I tried to implement this on the httpcore level, figuring that it'd be nice to go ahead and support anything that depended on httpcore. I still think that would be a good way to approach this, perhaps even supplanting the httpx-specific approach. However, httpcore's connection interfaces are significantly more complex to mock, if only because whereas httpx has only two entrypoints, httpcore technically has 8, an HTTP1, HTTP1.1 and HTTP2, and a connection pool connection for both sync and async requests (luckily all the supported proxy request types are implemented over top the other four and wouldn't require their own interceptors). Additionally, it wasn't entirely clear to me whether merely mocking the "handle request" method was sufficient to prevent outbound network connections for all 8 of these connection types.
For the sake of having support for HTTPX at least, and not holding it back by trying to support a broader, I chose to stick to just supporting HTTPX for the time being. The implementation luckily turned out to be pretty simple, and I took a helpful queue from the excellent https://github.com/Colin-b/pytest_httpx, specifically the idea to mock the
_transport_for_url
method, which prevents any of the httpcore complexity from leaking into this feature.