Skip to main content

pytest plugin for SQL pipeline testing with DuckDB — load fixtures, run queries, snapshot results

Project description

pytest-duckdb

CI PyPI Python

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 .sql files 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.csvorders 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


Download files

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

Source Distribution

pytest_duckdb-0.1.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

pytest_duckdb-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for pytest_duckdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5f10ac2c970e03824bc0f20e5f06d06cc039670015ee0e9973e715607443189e
MD5 831450f701a2499a09704ec5d063cb02
BLAKE2b-256 42bd5acaed74baa58b1f3116c0a485ee51bb23b3cacf708e1256775191edfa4e

See more details on using hashes here.

Provenance

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

Publisher: ci.yml on AnnasMazhar/pytest-duckdb

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_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

Hashes for pytest_duckdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e798faa7b6b287dbec6c84965b934af176c04851eb6e8467a4ceb288036b0413
MD5 b3e973f6afadd3adad07a3e91ac7d4d2
BLAKE2b-256 36409a4a5aeb97827e20622d7000844a809d5e16f928f58589e620d77ce789a2

See more details on using hashes here.

Provenance

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

Publisher: ci.yml on AnnasMazhar/pytest-duckdb

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page