Not every failed test should stop a pipeline. A handful of orders with a strange status deserve a look,
but the dashboards can still be built. severity: warn turns a test into a warning, and warn_if and
error_if set thresholds, so a few bad rows warn and many bad rows fail.
Copy and paste
One test:
- name: status
data_tests:
- accepted_values:
arguments:
values: ['placed', 'shipped', 'returned']
config:
severity: warn
Warn from one bad row, fail from six:
- name: amount
data_tests:
- positive_value:
config:
warn_if: ">0"
error_if: ">5"
Every test in a folder, in dbt_project.yml:
data_tests:
shop:
staging:
+severity: warn
In a singular test file:
{{ config(severity='warn') }}
select ...
What the output looks like
WARN 1 positive_value_stg_orders_amount ..................... [WARN 1 in 0.01s]
[WARNING]: in test positive_value_stg_orders_amount (models/staging/_staging.yml)
[WARNING]: Got 1 result, configured to warn if >0
Done. PASS=5 WARN=1 ERROR=0 SKIP=0
How the settings combine
A test counts its failing rows and compares the count with two conditions:
- with
severity: error, the default, dbt checkserror_iffirst and thenwarn_if; - with
severity: warn, dbt checks onlywarn_if.
Both conditions default to !=0, so by default any failing row is an error. In the second example,
one negative amount gives a warning and six give an error.
Warnings and dbt build
A failed test makes dbt build skip the models that depend on the tested model. A warning does not: the
models downstream are built as usual, and the run ends with WARN=1 instead of ERROR=1. Use warnings
for data you want to know about, not for data that would make the results wrong.
Turning warnings back into errors
In CI you may want every warning to fail the job:
dbt build --warn-error
--warn-error-options limits that to specific kinds of warnings.
Tested with dbt Core 1.12.