Slide 10
Slide 10 text
Tests
Because testing everything your project does manually means you have to do it every time you change the
code
😱
tests/single.py
from fastapi.testclient import TestClient
from python_api_template.main import app
client = TestClient(app)
def test_single():
response = client.post("/", json={"id": "foo", "message": "hello world"})
assert response.status_code == 200
pytest tests/single.py
============================================= test session starts ==============================================
platform darwin -- Python 3.11.8, pytest-8.0.0, pluggy-1.4.0
rootdir: /Users/kahnwong/Git/kahnwong/platform/python-api-template
plugins: cov-4.1.0, xdist-3.5.0, anyio-4.2.0
collected 1 item