rglsk, updated 🕥 2023-01-09 20:23:37

SQLAlchemy ORM 1.4 with FastAPI on asyncio

This is a tutorial app build for my blog post

Run project

docker-compose up

Run tests

docker-compose run app pytest

Generate migrations

docker-compose run app alembic revision --autogenerate

Run migrations

docker-compose run app alembic upgrate head


Refactor tests to run in SQLAlchemy transactions

opened on 2023-01-09 20:20:50 by bharling

This PR alters to do the database setup once at the start of the test run, then execute each test case inside a transaction that is rolled back automatically at the end of each test. This speeds things up a fair bit.

Also, a dedicated test database is created and destroyed for each test run, which avoids clearing data in the local db

Finally - database tables are created by explicitly running the alembic migrations rather than via the metadata. This ensures that migrations are also tested.

Updated a few dependencies along the way

Piotr Rogulski

🐍 Senior Software Engineer @ Passionate pythonista, focused on new technologies and problem-solving.

GitHub Repository

python sqlalchemy asyncio fastapi