Support async engines#11
Merged
Merged
Conversation
Split setup fixtures to sync/async and different scopes. Refactor database manager to better support async workflow.
Closed
There was a problem hiding this comment.
Pull request overview
This PR adds async SQLAlchemy engine support to pytest-sqlalchemy-alembic, including async-capable database provisioning and updated examples/CI to validate async drivers.
Changes:
- Add async engine handling in plugin configuration and database manager layer (AsyncEngine + async DB lifecycle helpers).
- Extend supported dialect driver mappings to include common async drivers (asyncpg/aiosqlite/asyncmy/aiomysql).
- Add a new async example project and update CI/workflows to run it for async driver matrices.
Reviewed changes
Copilot reviewed 38 out of 44 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pytest_sqlalchemy_alembic/utils.py | Switch Alembic upgrade to accept a URL and run migrations in a separate thread for async env.py support. |
| src/pytest_sqlalchemy_alembic/plugin.py | Add async-aware setup paths and introduce engine scope selection via ini. |
| src/pytest_sqlalchemy_alembic/dialects/sqlite.py | Refactor SQLite manager to produce test DB URLs and accept a connection for DB ops. |
| src/pytest_sqlalchemy_alembic/dialects/postgresql.py | Refactor Postgres manager to separate connection creation from DB operations and support async engines. |
| src/pytest_sqlalchemy_alembic/dialects/mariadb.py | Refactor MariaDB/MySQL manager to accept a connection for DB ops and support async engines. |
| src/pytest_sqlalchemy_alembic/dialects/base.py | Add unified sync/async engine creation, DB provisioning, table creation, and disposal helpers. |
| src/pytest_sqlalchemy_alembic/dialects/init.py | Mark async driver variants as supported by mapping them to existing managers. |
| src/pytest_sqlalchemy_alembic/config.py | Add AsyncEngine + async_sessionmaker support and new sqlalchemy_engine_scope parsing. |
| README.md | Document pytest-asyncio as an optional dependency and update dialect support list. |
| pyproject.toml | Add optional deps groups (async, xdist) and tighten mypy configuration. |
| example_project/uv.lock | Update example lockfile metadata/extras to match new optional dependency layout. |
| example_project/pyproject.toml | Reorder/clean optional dependencies and tighten mypy settings for the example project. |
| example_project/example_project/tests/test_db.py | Add return type annotation to test. |
| example_project/example_project/tests/test_create_user.py | Adjust imports and update query style to modern SQLAlchemy select() usage. |
| example_project/example_project/tests/conftest.py | Add typing and explicit Session return type for fixture. |
| example_project/example_project/models.py | Remove redundant file header comment. |
| example_project/example_project/db.py | Add typing for session generators/context manager. |
| example_project/alembic/script.py.mako | Remove docstrings from generated upgrade/downgrade template. |
| example_project/alembic/env.py | Import models instead of db to ensure metadata is loaded. |
| example_project_async/pyproject.toml | Add new async example project with async drivers and pytest-asyncio configuration. |
| example_project_async/Makefile | Add helper targets for starting/stopping local DB containers. |
| example_project_async/example_project_async/tests/test_db.py | Add async example test validating AsyncEngine binding. |
| example_project_async/example_project_async/tests/test_create_user.py | Add async example test covering async CRUD and scalar select. |
| example_project_async/example_project_async/tests/conftest.py | Add async session fixture for async example project. |
| example_project_async/example_project_async/tests/init.py | Add package marker for async tests. |
| example_project_async/example_project_async/models.py | Add async example ORM model. |
| example_project_async/example_project_async/main.py | Add async example app entry point and async create_user implementation. |
| example_project_async/example_project_async/db.py | Add async engine/sessionmaker and async DB context manager for example. |
| example_project_async/example_project_async/config.py | Add pydantic-settings config for async example. |
| example_project_async/example_project_async/init.py | Add package marker for async example. |
| example_project_async/docker-compose.yml | Add Postgres/MariaDB services for async example project. |
| example_project_async/alembic/versions/2026-06-17_679fe935495c_create_users.py | Add initial migration for async example project. |
| example_project_async/alembic/versions/init.py | Add package marker for async Alembic versions. |
| example_project_async/alembic/script.py.mako | Add Alembic script template for async example project. |
| example_project_async/alembic/env.py | Add async Alembic env.py using async engine and asyncio.run migration runner. |
| example_project_async/alembic/init.py | Add package marker for async Alembic config. |
| example_project_async/.gitignore | Ignore local SQLite DB files for async example project. |
| .pre-commit-config.yaml | Switch mypy hooks to uv run mypy and add hooks for both example projects. |
| .github/workflows/dialect-sqlite.yml | Add aiosqlite to matrix and route runs to correct example project directory. |
| .github/workflows/dialect-postgresql.yml | Add asyncpg to matrix and route runs to correct example project directory. |
| .github/workflows/dialect-mysql.yml | Add async MySQL drivers to matrix and route runs to correct example project directory. |
| .github/workflows/dialect-mariadb.yml | Add async MariaDB/MySQL drivers to matrix and route runs to correct example project directory. |
| .github/workflows/ci.yml | Add mypy job for the async example project. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.