Bug: when using TestClient for testing an endpoint #11486
-
First Check
Commit to Help
Example Code@pytest.mark.asyncio
async def test_something(test_client):
response = test_client.get("/v1/rules/?custom=example.com&args=0&kwargs=0")
assert response is not None DescriptionI need to pass args and kwargs otherwise the test client returns 422. I've encountered the bug before where the test client returned 422 when x was not passed. Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.110.2 Pydantic Version2.7.0 Python VersionPython 3.12.1 Additional Contextb'{"detail":[{"type":"missing","loc":["query","args"],"msg":"Field required","input":null},{"type":"missing","loc":["query","kwargs"],"msg":"Field required","input":null}]}' |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Apr 25, 2024
Replies: 1 comment 3 replies
-
So basically parameters defined in dependency overrides get picked up as query parameters: def auth_service_mock_dependency(x):
pass
api_client.app.dependency_overrides[authentication_service] = auth_service_mock_dependency |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is
x
?You have to specify the type of this parameter and where FastAPI should look for it (Query, Path, Body, etc.)