Skip to content

15. Tests That Know What to Ignore

Difficulty: Hard · Topic: Data tests

Write models/schema.yml tests for customers (customer_id, email, is_test). The rules come with exceptions:

A test with severity warn still runs and reports its rows, but does not fail the build. On clean datasets nothing may fail (warnings are fine); on broken datasets at least one test must fail.

Your schema.yml tests run on 5 datasets, including hidden ones: clean datasets must pass every test, broken ones must make a test fail.

Clean data (clean)

Two QA accounts share an email; one customer signed up by phone.

{{ ref('customers') }}

customer_idemailis_test
1asha@example.comfalse
2qa@codefordata.intrue
3qa@codefordata.intrue
4nullfalse
5ravi@example.comfalse

Two real customers with one email (broken)

A signup bug created a second account for the same person.

{{ ref('customers') }}

customer_idemailis_test
1asha@example.comfalse
6asha@example.comfalse
2qa@codefordata.intrue

Hints

Hint 1Every test accepts a config: block. where: "not is_test" runs the test on the filtered rows only.
Hint 2severity: warn in the config turns a failing test into a warning.
Hint 3Put both under the email column: a unique test with config: {where: "not is_test"} and a not_null test with config: {severity: warn}.

Learn the concepts

More dbt problems

All dbt problems