I have a file called main.py
in which I put a POST
call with only one input parameter (integer). Simplified code is given below:
from fastapi import FastAPI
app = FastAPI()
@app.post("/do_something/")
async def do_something(process_id: int):
# some code
return {"process_id": process_id}
Now, if I run the code for the test, saved in the file test_main.py
, that is:
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_do_something():
response = client.post(
"/do_something/",
json={
"process_id": 16
}
)
return response.json()
print(test_do_something())
I get:
{'detail': [{'loc': ['query', 'process_id'], 'msg': 'field required', 'type': 'value_error.missing'}]}
I can't figure out what the mistake is. It is necessary that it remains a POST
call.