Skip to content
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

Incompatibility with httpx 0.28.0 #277

Closed
PriOliveira opened this issue Nov 29, 2024 · 4 comments · Fixed by #278
Closed

Incompatibility with httpx 0.28.0 #277

PriOliveira opened this issue Nov 29, 2024 · 4 comments · Fixed by #278

Comments

@PriOliveira
Copy link

When upgrading httpx from 0.27.2 to 0.28.0, the mocks that were previously correctly detected as mocked, stop being considered as so and raise an AllMockedAssertionError.

@PrieJos
Copy link

PrieJos commented Nov 29, 2024

Hi All,

For some reasons I couldn't find out, the httpcore mocker (respx.mocks.HTTPCoreMocker) is not being able to match the patterns for the mocked routes upon test function executions.

A workaround that is working for me at least is to switch to the httpx mocker (respx.mocks.HTTPXMocker) when starting the mock router. That may look like something similar in your tests to this:

# Build your mocked responses here
mocked_resp1 = ...
mocked_resp2 = ...
mocked_resp3 = ...

# Mocked API service
async with respx.mock(base_url=base_url_mock, using="httpx") as respx_mock:
    respx_mock.get("/", name="$service_document$").mock(mocked_resp1)
    respx_mock.get("/$metadata", name="$metadata$").mock(mocked_resp2)
    respx_mock.head("/", name="$csrf_token$").mock(mocked_resp3)
    yield respx_mock

The difference is the argument using="httpx" when opening the context manager.

Cheers
Jose M. Prieto

@ndhansen
Copy link
Contributor

Hey, I've raised a fix in #278, please let me know if that helps.

pawelad added a commit to pawelad/pymonzo that referenced this issue Dec 3, 2024
frankie567 added a commit to frankie567/httpx-oauth that referenced this issue Dec 6, 2024
jayaddison added a commit to openculinary/backend that referenced this issue Dec 13, 2024
@tomchristie
Copy link

Ooof that's frustrating.

Does it make more sense for us to switch back to str|bytes on our side, or leave the fix?change? to your side?

@lundberg
Copy link
Owner

Does it make more sense for us to switch back to str|bytes on our side, or leave the fix?change? to your side?

@tomchristie .. #278 solves this issue quite clean on our end, so I'll merge it as soon it's updated/linted and will push a new release asap

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 a pull request may close this issue.

5 participants