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

Show a diff of mocked requests and actually intercepted requests when raising AllMockedAssertionError #275

Open
dolfandringa opened this issue Oct 24, 2024 · 0 comments

Comments

@dolfandringa
Copy link

dolfandringa commented Oct 24, 2024

Unfortunately i can't reopen #250 but I ran into the issue again.
The issue is that respx gives a very nice error if a request was issued but not mocked. The problem is that with just this error it is hard to debug what is going on in the code under test. Normally (with pytest), it shows the diff between the actual and expected values of an assert statement, which really helps with debugging.
With respx we only get an error that a specific url was not mocked. But we don't get information on which intercepted requests were successfully mocked and what the difference is. It would be much easier to debug if there was some kind of diff showing all mocked and intercepted requests.

An example would be:

def test_diff(respx_mock: respx.MockRouter):
    url1="https://test.com/foo"
    url2="https://test.com/bar"
    url3="https://test.com/baz"
    respx_mock.get(url1).mock(return_value=Response(200))
    respx_mock.get(url2).mock(return_value=Response(200))
    response=httpx.get(url1)
    response=httpx.get(url3)

In this case it would be nice to show an error like:

AllMockedAssertionError: RESPX: <Request('GET', 'https://test.com/baz')> not mocked!
Expected:   <Request('GET', 'https://test.com/foo')>, <Request('GET', 'https://test.com/bar')> 
                                                                                                                                                              ^
Received:   <Request('GET', 'https://test.com/foo')>, <Request('GET', 'https://test.com/baz')> 
                                                                                                                                                              ^
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

No branches or pull requests

1 participant