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

Open
PriOliveira opened this issue Nov 29, 2024 · 2 comments · May be fixed by #278
Open

Incompatibility with httpx 0.28.0 #277

PriOliveira opened this issue Nov 29, 2024 · 2 comments · May be 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 ndhansen linked a pull request Nov 29, 2024 that will close this issue
@ndhansen
Copy link

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
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.

3 participants