Skip to main content

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:

  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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_pylembic-0.3.0.tar.gz (55.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_pylembic-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_pylembic-0.3.0.tar.gz.

File metadata

  • Download URL: pytest_pylembic-0.3.0.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for pytest_pylembic-0.3.0.tar.gz
Algorithm Hash digest
SHA256 df2e641d7567a00c066d51d57d782b2ba53dc15720eef9d2704261c23620b20b
MD5 580954b96f4e9d94f44356bbb67e1625
BLAKE2b-256 48e94eb68da0a44de52001d59d70d296e4af37e4dc7bc2e04d02a4f16f895a21

See more details on using hashes here.

File details

Details for the file pytest_pylembic-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_pylembic-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84f7fd9817db4abbc46a6179559c8a60568cd7ca417c89aa3750a9a2c4d25164
MD5 31b4102af9d1659da325015fd365a40f
BLAKE2b-256 9287ca493f3325a0c15131f40d131109581432be7fd8676c28bcb1bb397ac464

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page