🧪 pytest-pylembic
A pytest plugin for validating Pylembic database migrations automatically.
📝 Overview
pytest-pylembic is a pytest plugin that integrates with pylembic to automatically validate your Pylembic database migrations during test runs. This plugin makes it easy to ensure your migration files:
- Have no duplicate revision IDs
- Maintain a linear history (or properly branched history)
- Correctly define dependencies between migrations
- Follow proper formatting conventions
📦 Installation
pip install pytest-pylembic
⚙️ Usage
Once installed, the plugin automatically runs migration validation when you execute pytest. No additional configuration is required if your migrations are in the standard migrations directory.
💻 Command Line Options
You can customize the plugin's behavior with these pytest command line options:
pytest --alembic-migrations-dir=path/to/migrations # Specify a custom migrations directory
pytest --skip-pylembic # Skip migration validation
pytest --pylembic-detect-branches=False # Disable branch detection
pytest --pylembic-verbose=False # Disable verbose output
⚙️ Configuration in pytest.ini
You can also configure these options in your pytest.ini file:
[pytest]
addopts = --alembic-migrations-dir=alembic_migrations_dir --pylembic-detect-branches=False --pylembic-verbose
🔍 Examples
▶️ Basic Usage
Simply run pytest as usual:
pytest
The plugin will automatically validate your migrations and report any issues.
🛠️ Custom Configuration
For a project with migrations in a non-standard location:
pytest --alembic-migrations-dir=database/migrations
⚡ How It Works
This plugin leverages the pylembic library to perform validation on your Pylembic migrations. It automatically:
- Adds a virtual test that runs before your other tests
- Validates the migration files using the Validator class from pylembic
- Reports any issues as test failures
- Provides a summary of migration validation in the test report
📋 Requirements
- Python 3.11+
- pylembic
🪪 License
MIT License
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📧 Contact
(c) 2025, Created with ❤️ by Marco Espinosa
Metadata
Release files for pytest-pylembic 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_pylembic-0.4.0.tar.gz | 55.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_pylembic-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.0 kB
Release files / pytest_pylembic-0.4.0.tar.gz
| Download URL | pytest_pylembic-0.4.0.tar.gz |
|---|---|
| Size | 55.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bff2e481587ebb4619f6e56044011eb067774e5ef2f6f17ccb2a5cfda5d74f6
|
|
BLAKE2b-256 checksum How to use checksums |
ffcc430cfd9b62bf58e04c5b39a46f6a924174bab239c23b098f70931f3fcc76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytest_pylembic-0.4.0-py3-none-any.whl
| Download URL | pytest_pylembic-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfe1d17dce062a54fcda61d924cbafc7e523a1c6676a0a293289dc19abe3d94a
|
|
BLAKE2b-256 checksum How to use checksums |
fc2054e13557a1792e1638eee1553cb0287c87f3d513b4c062b061834685705e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|