This repository is a simple example application of how to test asynchronous FastAPI routes using a Docker instance of PostgreSQL with asyncpg
as the database driver. It is done by using testcontainers-python.
You can check a more detailed text about the repository here.
This repo was created using uv and uses Python version 3.12.3.
-
Clone the repo locally and access the project folder:
git clone https://github.com/lealre/fastapi-testcontainer-asyncpg.git cd fastapi-testcontainer-asyncpg
-
Run the command to serve the API on port 8000. It will automatically create and activate the virtual environment:
uv run -m fastapi dev src/app.py
To test the endpoint, access
http://localhost:8000/docs
. -
Run the tests:
uv run pytest -vv