-
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
assert_all_mocked wrongly reports a route as not mocked? #196
Comments
Ah, I think this is my misuse of the decorator? My test ought to be:
which passes as expected. |
Yep, you spot the issue! When passing args (configuring) to the decorator, you need to add the mocked routes to that router, i.e. using the Thanks for bringing up the issue anyways, it can help others bumping in to the same "problem". Maybe RESPX should fire a warning when the test function is missing the |
Thanks - I then fell over this issue https://pythonissues.com/issues/1027354, but switched to the pytest.mark.respx decorator instead and all is well now. A warning could certainly be helpful. Happy for this to be closed, depending on what you decide about the warning. |
I'll open a new issue about the warning, thanks. |
I'm using respx to mock various http get/post requests for testing, and my tests are all behaving as expected. But when I set assert_all_mocked=True, it asserts that a route is not mocked when I believe it is.
This test demonstrates an equivalent problem:
It fails with:
respx.models.AllMockedAssertionError: RESPX: <Request('POST', 'http://example.com/test')> not mocked!
However, this test passes:
suggesting that the call is mocked.
This test:
fails, because assert_all_mocked's automock gets involved, and the POST request returns a Response[200] with no JSON-able data.
The text was updated successfully, but these errors were encountered: