https://github.com/lealre/fastapi-testcontainer-asyncpg
Testing async FastAPI routes with PostgreSQL and asyncpg using testcontainers-python.
https://github.com/lealre/fastapi-testcontainer-asyncpg
asyncpg fastapi pytest pytest-asyncio sqlalchemy testcontainers
Last synced: 3 months ago
JSON representation
Testing async FastAPI routes with PostgreSQL and asyncpg using testcontainers-python.
- Host: GitHub
- URL: https://github.com/lealre/fastapi-testcontainer-asyncpg
- Owner: lealre
- Created: 2024-12-09T12:06:15.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-12-31T10:27:35.000Z (6 months ago)
- Last Synced: 2025-04-09T15:10:57.594Z (3 months ago)
- Topics: asyncpg, fastapi, pytest, pytest-asyncio, sqlalchemy, testcontainers
- Language: Python
- Homepage: https://lealre.github.io/fastapi-testcontainer-asyncpg/
- Size: 950 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Testcontainers with FastAPI and asyncpg
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](https://github.com/testcontainers/testcontainers-python).
You can check a more detailed text about the repository [here](https://lealre.github.io/fastapi-testcontainer-asyncpg/).
## How to run this project
This repo was created using [uv](https://docs.astral.sh/uv/) and uses Python version 3.12.3.
[How to install uv](https://docs.astral.sh/uv/getting-started/installation/).
1. Clone the repo locally and access the project folder:
```bash
git clone https://github.com/lealre/fastapi-testcontainer-asyncpg.git
cd fastapi-testcontainer-asyncpg
```2. Run the command to serve the API on port 8000. It will automatically create and activate the virtual environment:
```bash
uv run -m fastapi dev src/app.py
```To test the endpoint, access `http://localhost:8000/docs`.
3. Run the tests:
```bash
uv run pytest -vv
```