pytest-alembic is a pytest plugin designed to verify Alembic database migrations. It provides fixtures and test functions to ensure that migrations can be applied and reverted correctly, that the database schema remains consistent, and that the migration history is valid. The library is actively maintained, with frequent minor releases addressing compatibility and bug fixes, typically on a monthly or bi-monthly basis.
pip install pytest-alembicVerified import paths — ran on the pinned version, not inferred.
To get started, define `alembic_config` and `alembic_engine` fixtures in your `conftest.py`. The `alembic_config` fixture should point to your Alembic configuration file and script location. The `alembic_engine` fixture should return a SQLAlchemy engine configured for a test database. Once these are set, you can write pytest functions that use the `alembic_runner` fixture to interact with and test your migrations. Run pytest with the plugin installed, and it will automatically discover tests.
Upgrade `pytest-alembic` to version `0.11.0` or newer to ensure compatibility with `pytest >= 8.0.0`.
Upgrade `pytest-alembic` to version `0.12.1` or newer for proper handling of `pyproject.toml` based Alembic configurations.
Ensure you are using `pytest-alembic` version `0.10.7` or newer for robust SQLAlchemy 2.0 compatibility.
Upgrade `pytest-alembic` to version `0.12.0` or newer to ensure proper handling and testing of branched revisions, where each branch head is upgraded individually.
Review your `conftest.py` and pytest command-line arguments. The plugin now automatically discovers tests by default or uses the `pytest_alembic_test_paths` hook to configure test registration paths.