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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdcaa0fed196f8d9c1054ecba5f6f1ceb1b5a37de3d3d1b154f031dfa14160dd
|
|
| MD5 |
cf69f8075c79b8b34912e40a0882d152
|
|
| BLAKE2b-256 |
78c55b9869458edca68d27d61b5f93c9b4a4a593c9c4e480ca22ceef401dbbec
|
Provenance
The following attestation bundles were made for pytest_dblift-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on dblift/dblift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_dblift-0.1.0.tar.gz -
Subject digest:
cdcaa0fed196f8d9c1054ecba5f6f1ceb1b5a37de3d3d1b154f031dfa14160dd - Sigstore transparency entry: 2582616966
- Sigstore integration time:
-
Permalink:
dblift/dblift@fd901a645a8a09125b05ade42ff7eaf1fff7dd33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dblift
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@fd901a645a8a09125b05ade42ff7eaf1fff7dd33 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4ad36a73081f97771c4978320090fd52b97d01ddc272e8a4cb7c9958a8300d1
|
|
| MD5 |
c197d62d8c3c8911cb04bc44c8d0f46b
|
|
| BLAKE2b-256 |
88a910438499d34773033148d1730500d9dbdd2de155e664392b8a3d7691c273
|
Provenance
The following attestation bundles were made for pytest_dblift-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on dblift/dblift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_dblift-0.1.0-py3-none-any.whl -
Subject digest:
e4ad36a73081f97771c4978320090fd52b97d01ddc272e8a4cb7c9958a8300d1 - Sigstore transparency entry: 2582616971
- Sigstore integration time:
-
Permalink:
dblift/dblift@fd901a645a8a09125b05ade42ff7eaf1fff7dd33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dblift
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@fd901a645a8a09125b05ade42ff7eaf1fff7dd33 -
Trigger Event:
workflow_dispatch
-
Statement type: