Skip to content

Support async engines#11

Merged
Nnonexistent merged 6 commits into
mainfrom
2-support-async-engines
Jun 18, 2026
Merged

Support async engines#11
Nnonexistent merged 6 commits into
mainfrom
2-support-async-engines

Conversation

@Nnonexistent

Copy link
Copy Markdown
Owner

No description provided.

@Nnonexistent Nnonexistent self-assigned this Jun 18, 2026
@Nnonexistent Nnonexistent linked an issue Jun 18, 2026 that may be closed by this pull request
@Nnonexistent Nnonexistent requested a review from Copilot June 18, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/pytest_sqlalchemy_alembic/plugin.py
Comment thread src/pytest_sqlalchemy_alembic/plugin.py Outdated
Comment thread src/pytest_sqlalchemy_alembic/utils.py
Comment thread src/pytest_sqlalchemy_alembic/config.py
Comment thread src/pytest_sqlalchemy_alembic/config.py
@Nnonexistent Nnonexistent merged commit 23c010d into main Jun 18, 2026
26 checks passed
@Nnonexistent Nnonexistent deleted the 2-support-async-engines branch June 18, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support async engines

2 participants