-
Notifications
You must be signed in to change notification settings - Fork 31
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
Allow usage with httpx.MockTransport
#167
Comments
Hello @CarliJoy , I am not sure to follow, why can't this be achieved with the |
Hi colin-b, Got it, we were using an older version with only the We still need to patch a specific client for our use case. We provide a pytest fixture as a plugin for our service, and users often want to mock additional services with However, using a global mocking state creates issues:
Additionally, different service tests might require varying options for |
Your shared_mocked_hosts = ["default_mocked_host"]
def should_mock(request: httpx.Request) -> bool:
return request.url.host in shared_mocked_hosts The other options are evaluated only for mocked requests so it should be fine as well I assume? |
Sorry for the late reply. The suggested solution sounds very cumbersome for our use case. Having a good Or expressed differently: Having the possibility the transport of selected clients instead of patching transports globally would be a very nice thing for more complex API tests. |
In certain use cases,
pytest_httpx
is used only to mock a single httpx client, specifically one responsible for connecting to a cluster of servers for serviceA
. However, while mocking this specific client, we still want the flexibility to make normal, non-mocked requests to other services without impacting the entire environment.Previously, we initialized
HTTPXMock
directly, but with recent changes, this is no longer supported. While the focus on clean interfaces is understandable, this change limits the ability to easily create single mocked clients while keeping other requests unaltered.To address this, I propose adding support for a MockTransport, as outlined below:
The
MockedTransport
class extends integrate smoothly withHTTPXMock
, allowing targeted client mocking while enabling other clients to make live requests as usual.The text was updated successfully, but these errors were encountered: