This package provides pytest plugin for validating Alembic migrations using the pylembic package.
Project description
🧪 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_pylembic-0.2.0.tar.gz.
File metadata
- Download URL: pytest_pylembic-0.2.0.tar.gz
- Upload date:
- Size: 55.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8f93a8e423af686912835265bc7a8eb23b582d0320309a7e399d78b735fa102
|
|
| MD5 |
3db132cdfe7f064603b1f88d0898b6d1
|
|
| BLAKE2b-256 |
d58c22b711a0c24ea53d4b70de3ddb9162315c0df6c4320a0c870e38c3dbdef5
|
File details
Details for the file pytest_pylembic-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pytest_pylembic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef3f995fe1bf4fad2b4ca8f6e888a6e45a0122a23413cfc8e082ae1f6c49b8f0
|
|
| MD5 |
03193b6f68bfcd8910f164a40c6f591e
|
|
| BLAKE2b-256 |
afc405606ad3ab9ab74078e37d846fbedf9b545293cdc8ac0f75fbfcd76f16bc
|