feat: add _with_context variants for generic tests#975
Conversation
Adds six new elementary generic tests that extend common dbt/dbt_utils/dbt_expectations tests with a `context_columns` parameter, allowing users to specify which additional columns are returned alongside failing rows. If `context_columns` is omitted, all columns are returned. New tests: - elementary.not_null_with_context - elementary.accepted_range_with_context - elementary.expect_column_values_to_not_be_null_with_context - elementary.expect_column_values_to_be_unique_with_context - elementary.expect_column_values_to_match_regex_with_context - elementary.relationships_with_context Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
👋 @joostboon |
📝 WalkthroughWalkthroughAdds six new dbt generic test macros that accept optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- accepted_range_with_context: raise compiler error when both min_value and max_value are omitted, preventing a silent always-pass condition - expect_column_values_to_be_unique_with_context: use explicit column list from adapter.get_columns_in_relation instead of SELECT * to prevent the computed n_records window column from leaking into the output Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
context_columnsparametercontext_columnsis provided, only those columns (plus the tested column) are returned alongside failing rowscontext_columnsis omitted, all columns are returned (SELECT *)context_columnsemit aWARNINGlog and are skipped rather than raising an errorNew tests
elementary.not_null_with_contextdbt.not_nullelementary.accepted_range_with_contextdbt_utils.accepted_rangeelementary.expect_column_values_to_not_be_null_with_contextdbt_expectations.expect_column_values_to_not_be_nullelementary.expect_column_values_to_be_unique_with_contextdbt_expectations.expect_column_values_to_be_uniqueelementary.expect_column_values_to_match_regex_with_contextdbt_expectations.expect_column_values_to_match_regex(requiresdbt_expectationsinstalled)elementary.relationships_with_contextdbt.relationshipsUsage
Test plan
elementary.not_null_with_contexton a column with nulls — verify failing rows include the specified context columnscontext_columns— verify all columns are returnedcontext_columns— verify a WARNING is logged and the column is skipped without erroringelementary.relationships_with_contexton a column with broken FK references — verify context columns are correctly prefixed with the child aliaselementary.expect_column_values_to_be_unique_with_context— verify all individual duplicate rows are returned (not just the grouped count)🤖 Generated with Claude Code
Summary by CodeRabbit