Welcome to the FastAPI TDD Workshop! This repository contains a sample FastAPI application to demonstrate Test-Driven Development (TDD) practices.
This application is a simple FastAPI project that includes endpoints to manage posts. The project demonstrates how to use TDD to build and test FastAPI applications using pytest and SQLite.
- FastAPI for building APIs
- SQLAlchemy for ORM
- SQLite for the database
- Pytest for testing
Follow these steps to set up the project on your local machine.
- Python 3.10 or higher
- Git
git clone https://github.com/kumaravelabinbev/fastapi-tdd.git
cd fastapi-tdd
On macOS/Linux:
python3 -m venv venv
source venv/bin/activate
On Windows:
python3 -m venv venv
.\venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt
To start the FastAPI application:
uvicorn app.main:app --reload
The application will be available at http://127.0.0.1:8000
.
To run the tests using pytest:
pytest
This will discover and run all tests in the project.
fastapi-tdd-workshop/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── models.py
│ ├── schemas.py
│ └── ...
├── tests/
│ ├── __init__.py
│ └── conftest.py
├── requirements.txt
├── README.md
└── ...
- app/: Contains the FastAPI application code.
- tests/: Contains the test cases for the application.
- requirements.txt: Lists the Python dependencies for the project.
- README.md: This file.