We just want to add an example for using error_if to assert the expectation that a test will fail. This is helpful in integration testing for dbt packages like dbt_utils.
Here is an example of using error_if in a clever way.
Explanation
By default, dbt treats:
0 row as PASS
>0 rows as FAIL
Overriding the config to error_if: "<1" will invert that. To the best of my knowledge, this feature was discovered rather than designed, and it also requires adding warn_if: "<0" to work properly.
Reviewers/Stakeholders/SMEs
Dee bEighty Ten
Related GitHub issues
No response
Additional information
By default for dbt data tests:
!=0 rows will FAIL (explicitly)
0 row will PASS (implicitly)
Overriding the config to error_if: "<1" will invert the default logic so that:
0 row will FAIL (explicitly)
!=0 rows will PASS (implicitly)
This also requires adding warn_if: "<0" to work properly. Otherwise, the default warning condition will still take effect. Overriding warn_if in this way takes it out of play since there should never be less than 0 rows returned.
Link to the page(s) on docs.getdbt.com requiring updates
We have docs for configuring
severity
for data tests:https://docs.getdbt.com/reference/resource-configs/severity
We just want to add an example for using
error_if
to assert the expectation that a test will fail. This is helpful in integration testing for dbt packages like dbt_utils.Tell us more about this update
Question:
Answer:
Reviewers/Stakeholders/SMEs
Dee bEighty Ten
Related GitHub issues
No response
Additional information
By default for dbt data tests:
!=0
rows willFAIL
(explicitly)0
row willPASS
(implicitly)Overriding the config to
error_if: "<1"
will invert the default logic so that:0
row willFAIL
(explicitly)!=0
rows willPASS
(implicitly)This also requires adding
warn_if: "<0"
to work properly. Otherwise, the default warning condition will still take effect. Overridingwarn_if
in this way takes it out of play since there should never be less than 0 rows returned.