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].

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.

Download files

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

Source Distribution

pytest_dblift-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

pytest_dblift-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_dblift-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_dblift-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytest_dblift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdcaa0fed196f8d9c1054ecba5f6f1ceb1b5a37de3d3d1b154f031dfa14160dd
MD5 cf69f8075c79b8b34912e40a0882d152
BLAKE2b-256 78c55b9869458edca68d27d61b5f93c9b4a4a593c9c4e480ca22ceef401dbbec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_dblift-0.1.0.tar.gz:

Publisher: publish-pypi.yml on dblift/dblift

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_dblift-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_dblift-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytest_dblift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4ad36a73081f97771c4978320090fd52b97d01ddc272e8a4cb7c9958a8300d1
MD5 c197d62d8c3c8911cb04bc44c8d0f46b
BLAKE2b-256 88a910438499d34773033148d1730500d9dbdd2de155e664392b8a3d7691c273

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_dblift-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on dblift/dblift

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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