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.
Metadata
Release files for pytest-dblift 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_dblift-0.1.1.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_dblift-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / pytest_dblift-0.1.1.tar.gz
| Download URL | pytest_dblift-0.1.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b240a30afa5a4374017185978a821de493668196da416b95c10d1b32aa53063
|
|
BLAKE2b-256 checksum How to use checksums |
6eae9d7780e5a88ce86cc7952b6041339bf9a82cc7504e58ecc600eee2145148
|
| 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 20, 2026.
Transparency logRelease files / pytest_dblift-0.1.1-py3-none-any.whl
| Download URL | pytest_dblift-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47b86de2fed386f5876bde74adfda144aa9eec4ae55efd633797efb32b774494
|
|
BLAKE2b-256 checksum How to use checksums |
33c21357fb9cd5691804ecaa4fc475d22cfb8514c56643b9976a5ff7310efd2e
|
| 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 20, 2026.
Transparency log