--- id: pytest-alembic version: "0.12.1" license: MIT license_treatment: permissive maintenance: active --- # pytest-alembic — A pytest plugin for verifying alembic migrations. License: permissive · Maintenance: active · Downloads: 1.3M/mo ## What it is and what it does pytest-alembic is a pytest plugin that automates testing of alembic database migrations. It provides four built-in tests that catch common migration mistakes: ensuring a single head revision exists (no diverged history), verifying the full upgrade path works, confirming migrations match your SQLAlchemy model definitions, and validating that downgrades succeed. Beyond these defaults, it offers fixtures like `alembic_runner` to write custom tests for complex data migrations, letting you practice test-driven development on tricky migration logic before running against production. The plugin sits between pytest and your alembic environment, running migrations in a test database and asserting their correctness. It solves real problems: catching forgotten migrations before merge, detecting migration failures with existing data, and preventing broken deployments from conflicting migrations merged in parallel. Most projects need minimal setup beyond what alembic itself requires. Use it for: - Catch forgotten migrations in CI before they reach production by asserting model definitions match the migration history. - Test complex data migrations with custom logic using the alembic_runner fixture to set up state and verify outcomes. - Detect diverged migration histories from merge conflicts automatically rather than discovering them during deployment. - Validate that all migrations can be reversed cleanly, ensuring your database can roll back if needed. - Ensure all SQLAlchemy models are properly imported and registered so autogenerate captures the full schema. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. A pytest plugin that runs built-in and custom tests against alembic database migrations to catch common issues like missing migrations, merge conflicts, and data-loss bugs. Yes. This package solves a real class of production bugs (broken migrations, merge conflicts, forgotten migrations) with low install friction and active maintenance. If you use alembic and SQLAlchemy, the built-in tests alone provide immediate value in CI. The custom test fixtures add flexibility for complex migrations. No known vulnerabilities, permissive license, and steady releases since 2020 make it a safe, practical choice. ## Install pip install pytest-alembic uv add pytest-alembic poetry add pytest-alembic ## Installing pytest-alembic Before you install: Low friction: pure Python wheel with three well-established runtime dependencies (pytest, alembic, sqlalchemy). Active maintenance with a recent commit on 2026-07-27 and steady release history since 2020-04-02. License in practice: MIT license is permissive; you can use this package freely in commercial and open-source projects with minimal restrictions. Quickstart: pip install pytest-alembic # In your project with alembic migrations configured: pytest --test-alembic # Or write a custom test: from pytest_alembic import alembic_runner def test_my_migration(alembic_runner): alembic_runner.migrate_up_before('revision_id') # ... setup data ... alembic_runner.migrate_up_one() Requires an existing alembic migration environment configured in your project; pytest-alembic integrates with it rather than setting it up from scratch. Verify before relying: - Whether the built-in tests (single_head_revision, upgrade, model_definitions_match_ddl, up_down_consistency) run automatically or require explicit configuration. - Exact setup boilerplate required beyond standard alembic initialization. - Whether experimental tests (all_models_register_on_metadata, downgrade_leaves_no_trace) are stable enough for production use. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 1.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags test alembic migrations, pytest database migration testing, alembic migration validation, sqlalchemy migration testing, database schema migration tests, alembic upgrade downgrade tests, migration conflict detection, database-migrations, sqlalchemy, ci-testing [View on SkillFed](https://skillfed.io/packages/pytest-alembic) · [View on PyPI](https://pypi.org/project/pytest-alembic/)