Skip to main content

pytest-dblift

pytest plugin for DBLift. It applies your migrations in tests and exposes a DBLiftClient.

This is a separate PyPI package, not dblift[pytest].

pytest-dblift 0.2.0 requires dblift 4.9.0 or later. dblift_validate calls DBLiftClient.validate in a way that dblift 4.8.0 does not accept.

Install

SQLite (default, stdlib driver):

pip install pytest-dblift

Any other engine: install the matching dblift extra so the native driver is present. The plugin does not install drivers and does not open a second connection — it calls create_engine(url) then DBLiftClient.from_sqlalchemy.

pip install pytest-dblift "dblift[postgresql]"
pytest --dblift-url "postgresql+psycopg://user:pass@localhost/app_test"

Quickstart

def test_schema(dblift_migrated_db, dblift_client):
    info = dblift_client.info()
    assert info.pending_migrations == []

dblift_migrated_db applies pending migrations (function scope). dblift_client is a session-scoped DBLiftClient. No fixture is autouse: request what you need.

Fixtures

Fixture Scope Role
dblift_config session Dict with url, migrations_dir, optional schema. Override in conftest.py.
dblift_engine session SQLAlchemy engine from that URL. Override to inject your app engine.
dblift_client session DBLiftClient.from_sqlalchemy(...).
dblift_migrated_db function client.migrate(), then yield the client.
dblift_empty_db function client.clean(clean_enabled=True), then yield the client.
dblift_validate function Callable: dblift_validate(**kwargs) runs client.validate and asserts success.
dblift_undo function Callable: dblift_undo(**kwargs) runs client.undo and asserts success. Does not migrate.

Undo uses companion U* scripts (same as dblift). There is no undo() function inside a V*.py file.

def test_rollback(dblift_migrated_db, dblift_undo):
    result = dblift_undo(target_version="0")
    assert result.success

Override config in tests/conftest.py:

import pytest

@pytest.fixture(scope="session")
def dblift_config():
    return {
        "url": "postgresql+psycopg://user:pass@localhost/app_test",
        "migrations_dir": "migrations",
    }

CLI options

Option What it does
--dblift-url Database URL when dblift_config is not overridden. Default: a temp SQLite file.
--dblift-migrations-dir One migrations directory (not a comma-separated list). Default: migrations.

pytest-xdist: only the default SQLite file is per-worker (test_gw0.db, …). A URL you pass with --dblift-url is used as-is.

Metadata

Release files for pytest-dblift 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-dblift 0.2.0
File Size Uploaded
pytest_dblift-0.2.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-dblift 0.2.0
File Interpreter ABI Platform
pytest_dblift-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / pytest_dblift-0.2.0.tar.gz

Download URL pytest_dblift-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4a50b1a9dd6f24708608f8106b19a168d424419ecb10e9314375fafb3c089102
BLAKE2b-256 checksum
How to use checksums
3fe90cb827e3a057e53f406f175e80450800408cb3487c198449a4603b1d5714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / pytest_dblift-0.2.0-py3-none-any.whl

Download URL pytest_dblift-0.2.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c180ec7764ceb1af9c7ec379e081c6433088a2fb794f20d4d7ccb19e1be32754
BLAKE2b-256 checksum
How to use checksums
0bd6caa4559575db2dc45d4bf9b48f1b0109523416153de5b5c8e06144195b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page