FastAPI हे TestClient (Starlette/httpx वर बनलेले) आणि त्याच्या dependency injection सिस्टमच्या कारणे अत्यंत चाचणीयोग्य आहे, जो मॉकिंग dependencies सोपे करते. चाचण्या सामान्यतः pytest आणि TestClient वापरुन अॅपला विनियोग सर्व्हरशिवाय विनंत्या पाठवतात.
TestClient सह मूळ endpoint चाचणी
fastapi.testclient TestClient
main app
client = TestClient(app)
():
response = client.get()
response.status_code ==
response.json() == {: }
():
response = client.post(, json={: , : })
response.status_code ==
response.json()[] ==
():
response = client.post(, json={: })
response.status_code ==
