Metadata-Version: 2.4
Name: pytest-pylembic
Version: 0.2.0
Summary: This package provides pytest plugin for validating Alembic migrations using the pylembic package.
Author-email: Marco Espinosa <marco@marcoespinosa.com>
License: MIT License
        
        Copyright (c) 2025 Marco Espinosa
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: pylembic>=0.7.0
Description-Content-Type: text/markdown

<!-- Shields -->
<p align="center">
<a href="https://github.com/maekind/pytest-pylembic"><img src="https://img.shields.io/github/actions/workflow/status/maekind/pytest-pylembic/.github%2Fworkflows%2Ftesting.yaml?label=tests&color=green" hspace="5"></a>
<a href="https://github.com/maekind/pytest-pylembic/releases"><img src="https://img.shields.io/github/actions/workflow/status/maekind/pytest-pylembic/.github%2Fworkflows%2Frelease.yaml?label=build%20package&color=green" hspace="5"></a>
<a href="https://pypi.org/project/pytest-pylembic"><img src="https://img.shields.io/github/v/release/maekind/pytest-pylembic?color=blue&label=pypi" hspace="5"></a>
<br>
<a href="https://github.com/maekind/pytest-pylembic/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-orange.svg" hspace="5"></a>
<a href="https://github.com/maekind/pytest-pylembic"><img src="https://img.shields.io/github/repo-size/maekind/pytest-pylembic?color=red" hspace="5"></a>
<a href="https://github.com/maekind/pytest-pylembic"><img src="https://img.shields.io/github/last-commit/maekind/pytest-pylembic?color=black" hspace="5"></a>
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/github/languages/top/maekind/pytest-pylembic?color=darkgreen" hspace="5"></a>
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python%20version-%3E3.11-lightblue" hspace="5"></a>
</p>
<!-- End of Shields -->

# 🧪 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

```bash
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:

```bash
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:

```ini
[pytest]
addopts = --alembic-migrations-dir=alembic_migrations_dir --pylembic-detect-branches=False --pylembic-verbose
```

## 🔍 Examples

### ▶️ Basic Usage

Simply run pytest as usual:

```bash
pytest
```

The plugin will automatically validate your migrations and report any issues.

### 🛠️ Custom Configuration

For a project with migrations in a non-standard location:

```bash
pytest --alembic-migrations-dir=database/migrations
```

## ⚡ How It Works

This plugin leverages the `pylembic` library to perform validation on your Pylembic migrations. It automatically:

1. Adds a virtual test that runs before your other tests
2. Validates the migration files using the Validator class from pylembic
3. Reports any issues as test failures
4. 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](mailto:marco@marcoespinosa.com)
