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:
customer_idis unique and never missing. A violation must stop the pipeline.- Emails are unique among real customers. QA test accounts (
is_test = true) share a handful of emails, and that is fine. - A missing email should be reported as a warning but must not stop the pipeline: some customers sign up with a phone number only.
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_id | is_test | |
|---|---|---|
| 1 | asha@example.com | false |
| 2 | qa@codefordata.in | true |
| 3 | qa@codefordata.in | true |
| 4 | null | false |
| 5 | ravi@example.com | false |
Two real customers with one email (broken)
A signup bug created a second account for the same person.
{{ ref('customers') }}
| customer_id | is_test | |
|---|---|---|
| 1 | asha@example.com | false |
| 6 | asha@example.com | false |
| 2 | qa@codefordata.in | true |
Hints
Hint 1
Every test accepts aconfig: block. where: "not is_test" runs the test on the filtered rows only.Hint 2
severity: warn in the config turns a failing test into a warning.Hint 3
Put both under the email column: aunique test with config: {where: "not is_test"} and a not_null test with config: {severity: warn}.Learn the concepts
- Data tests · 5 min read. unique, not_null, accepted_values and relationships, singular tests, and how a test fails: it returns rows.