FastAPI primer
This FastAPI starter template provides a simple and efficient way to begin a new web project, including preconfigured setup for test-driven development (TDD).
Features:
- unit/e2e and mutation testing
- CORS preconfigured
- sample allowed-origins
- example routing in submodule
- black code formatter
Usage
Requirements
- python3
- pipenv
Install
git clone https://github.com/builder555/fastapi-starter-tdd
cd fastapi-starter-tdd
pipenv install --dev
Run tests
# unit/e2e test
pipenv run test
# app/tests/test_main.py .
# app/tests/test_module.py .
# mutation test
pipenv run mutation
# 1. Running tests without mutations
# β Running...Done
#
# 2. Checking mutants
# β Ή 21/21 π 12 β° 0 π€ 0 π 9 π 0
# see results
pipenv run mutresult
Start a dev server
pipenv run start:dev
Navigate to http://localhost:8000/docs to see the Swagger UI or http://localhost:8000/redoc to see ReDoc.
To monitor tests while developing, run
pipenv run testmon
Structure
βββ app #<-- all your modules live here
β βββ __init__.py
β βββ module.py #<-- example module
β βββ tests #<-- unit/integration tests are here. these files are excluded from mutation
β βββ __init__.py
β βββ test_main.py
β βββ test_module.py
βββ main.py #<-- main application code
Running in a Docker container
docker build -t fastapi:latest . && docker run --rm -d -p 8000:8000 fastapi:latest
Navigate to http://localhost:8000/docs to see the Swagger UI or http://localhost:8000/redoc to see ReDoc.