Skip to main content

dbt-coverage

A CLI library with Python backend for computing docs and test coverage of dbt managed data warehouses.

Installation

pip install dbt-coverage

Usage

dbt-coverage comes with two basic commands: compute and compare. The documentation for the individual commands can be shown by using the --help option.

Compute

Compute coverage from target/catalog.json and target/manifest.json files found in a dbt project, e.g. jaffle_shop. You need to select documentation or test coverage by using the respective CLI argument.

$ cd jaffle_shop
$ dbt run  # Materialize models
$ dbt docs generate  # Generate catalog.json and manifest.json
$ dbt-coverage compute doc --cov-report coverage-doc.json  # Compute doc coverage, print it and write it to coverage-doc.json file

Coverage report
=====================================================================
customers                                              6/7      85.7%
orders                                                 9/9     100.0%
raw_customers                                          0/3       0.0%
raw_orders                                             0/4       0.0%
raw_payments                                           0/4       0.0%
stg_customers                                          0/3       0.0%
stg_orders                                             0/4       0.0%
stg_payments                                           0/4       0.0%
=====================================================================
Total                                                 15/38     39.5%

$ dbt-coverage compute test --cov-report coverage-test.json  # Compute test coverage, print it and write it to coverage-test.json file

Coverage report
=====================================================================
customers                                              1/7      14.3%
orders                                                 8/9      88.9%
raw_customers                                          0/3       0.0%
raw_orders                                             0/4       0.0%
raw_payments                                           0/4       0.0%
stg_customers                                          1/3      33.3%
stg_orders                                             2/4      50.0%
stg_payments                                           2/4      50.0%
=====================================================================
Total                                                 14/38     36.8%

Compare

Compare two coverage.json files generated by the compute command. This is useful to ensure that the coverage does not drop while making changes to the project.

$ dbt-coverage compare coverage-after.json coverage-before.json

# Coverage delta summary
              before     after            +/-
=============================================
Coverage      39.47%    38.46%         -1.01%
=============================================
Tables             8         8          +0/+0
Columns           38        39          +1/+0
=============================================
Hits              15        15          +0/+0
Misses            23        24          +1/+0
=============================================

# New misses
==============================================================
Catalog              15/38   (39.47%)  ->    15/39   (38.46%) 
==============================================================
- customers           6/7    (85.71%)  ->     6/8    (75.00%) 
-- new_col            -/-       (-)    ->     0/1     (0.00%) 
==============================================================

Combined use-case

$ cd my-dbt-project

$ dbt run  # Materialize models
$ dbt docs generate  # Generate catalog.json and manifest.json
$ dbt-coverage compute doc --cov-report before.json --cov-fail-under 0.5  # Fail if coverage is lower than 50%

# Make changes to the dbt project, e.g. add some columns to the DWH, document some columns, etc.

$ dbt docs generate
$ dbt-coverage compute doc --cov-report after.json --cov-fail-compare before.json  # Fail if the current coverage is lower than coverage in before.json
$ dbt-coverage compare after.json before.json  # Generate a detailed coverage delta report

Related packaged

https://github.com/mikaelene/dbt-test-coverage

License

Licensed under the MIT license (see LICENSE.md file for more details).

Metadata

Release files for dbt-coverage 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbt-coverage 0.1.4
File Size Uploaded
dbt-coverage-0.1.4.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbt-coverage 0.1.4
File Interpreter ABI Platform
dbt_coverage-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / dbt-coverage-0.1.4.tar.gz

Download URL dbt-coverage-0.1.4.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fb11f44ad8ef02e9f7e252fd340fbb2244f8e82b22e8787c4c71b96c653a2cfb
BLAKE2b-256 checksum
How to use checksums
991d953cf73a6364bf27dfa742d46900acd23f38d2010e4264f488aadec531e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Darwin/21.1.0

Release files / dbt_coverage-0.1.4-py3-none-any.whl

Download URL dbt_coverage-0.1.4-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af8a546158c3bb484952f07d1d2e543151594ab82c9aaf8156540b232de059c2
BLAKE2b-256 checksum
How to use checksums
8975c572877fbf9e5a0581cd17f62dea0609b3b3b36dee8fc60d5ff258515503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Darwin/21.1.0

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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