Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Assert an expected failure by overriding error_if #5719

Open
dbeatty10 opened this issue Jul 2, 2024 · 1 comment
Open

[Core] Assert an expected failure by overriding error_if #5719

dbeatty10 opened this issue Jul 2, 2024 · 1 comment
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core size: medium This change will take up to a week to address

Comments

@dbeatty10
Copy link
Contributor

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:

Is there a way to add integration tests to validate that the test fails appropriately?

Answer:

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.

@dbeatty10 dbeatty10 added content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core labels Jul 2, 2024
@nataliefiann nataliefiann added the size: medium This change will take up to a week to address label Sep 16, 2024
@nataliefiann
Copy link
Contributor

I've assigned a medium label to this while we we go through v.1.9 issues but I imagine this will take a day or two to doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core size: medium This change will take up to a week to address
Projects
None yet
Development

No branches or pull requests

2 participants