pytest plugin for SQL pipeline testing with DuckDB — load fixtures, run queries, snapshot results
Project description
pytest-duckdb
SQL pipeline testing made trivial. Load fixture CSVs as tables, run your queries, snapshot the results.
Install
pip install pytest-duckdb
Quick Start
Place CSV files in tests/fixtures/:
tests/
fixtures/
orders.csv
customers.csv
test_queries.py
They become tables automatically:
def test_revenue_query(duckdb_session, sql_snapshot):
result = duckdb_session.execute(
"SELECT * FROM orders WHERE amount > 100"
).fetchall()
# First run saves the snapshot, subsequent runs diff against it
sql_snapshot(result)
Features
- Zero config — fixture CSVs in
tests/fixtures/auto-load as tables - Snapshot testing — first run saves output, subsequent runs diff
- Raw SQL files — test
.sqlfiles directly without dbt - Ephemeral — each test gets a fresh in-memory DuckDB
- Fast — DuckDB is embedded, no Docker, no network
Fixture Loading
CSVs loaded by file stem become table names. orders.csv → orders table.
def test_join(duckdb_session):
result = duckdb_session.execute("""
SELECT c.name, o.amount
FROM orders o JOIN customers c ON o.customer_id = c.id
""").fetchall()
assert len(result) > 0
SQL File Testing
@pytest.mark.sql("queries/revenue_by_month.sql")
def test_revenue_by_month(sql_result, sql_snapshot):
sql_snapshot(sql_result)
Snapshot Update
Regenerate all snapshots when your expected output changes:
pytest --snapshot-update
License
MIT
Project details
Release history Release notifications | RSS feed
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_duckdb-0.1.0.tar.gz.
File metadata
- Download URL: pytest_duckdb-0.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f10ac2c970e03824bc0f20e5f06d06cc039670015ee0e9973e715607443189e
|
|
| MD5 |
831450f701a2499a09704ec5d063cb02
|
|
| BLAKE2b-256 |
42bd5acaed74baa58b1f3116c0a485ee51bb23b3cacf708e1256775191edfa4e
|
Provenance
The following attestation bundles were made for pytest_duckdb-0.1.0.tar.gz:
Publisher:
ci.yml on AnnasMazhar/pytest-duckdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_duckdb-0.1.0.tar.gz -
Subject digest:
5f10ac2c970e03824bc0f20e5f06d06cc039670015ee0e9973e715607443189e - Sigstore transparency entry: 1500579787
- Sigstore integration time:
-
Permalink:
AnnasMazhar/pytest-duckdb@c00bd1344a65e2d2f4867c34914c1c91ac6b606e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AnnasMazhar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@c00bd1344a65e2d2f4867c34914c1c91ac6b606e -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_duckdb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_duckdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e798faa7b6b287dbec6c84965b934af176c04851eb6e8467a4ceb288036b0413
|
|
| MD5 |
b3e973f6afadd3adad07a3e91ac7d4d2
|
|
| BLAKE2b-256 |
36409a4a5aeb97827e20622d7000844a809d5e16f928f58589e620d77ce789a2
|
Provenance
The following attestation bundles were made for pytest_duckdb-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on AnnasMazhar/pytest-duckdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_duckdb-0.1.0-py3-none-any.whl -
Subject digest:
e798faa7b6b287dbec6c84965b934af176c04851eb6e8467a4ceb288036b0413 - Sigstore transparency entry: 1500580063
- Sigstore integration time:
-
Permalink:
AnnasMazhar/pytest-duckdb@c00bd1344a65e2d2f4867c34914c1c91ac6b606e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AnnasMazhar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@c00bd1344a65e2d2f4867c34914c1c91ac6b606e -
Trigger Event:
release
-
Statement type: