Tests#
Note
The below checks require manifest.json to be present.
Checks related to model test coverage and test configuration.
Functions:
| Name | Description |
|---|---|
check_model_has_tests_by_name |
Models must have a minimum number of tests matching the specified test names. |
check_model_has_tests_by_type |
Models must have at least the specified number of schema tests and data tests. |
check_model_has_unique_test |
Models must have a test for uniqueness of a column. |
check_model_has_unit_tests |
Models must have more than the specified number of unit tests. |
check_model_test_coverage |
Set the minimum percentage of models that have at least one test. |
check_model_has_tests_by_name
#
Models must have a minimum number of tests matching the specified test names.
Rationale
Some teams require every model to have specific named tests — for example not_null on every primary-key column, or a custom accepted_values test. This check lets you enumerate the test names that must be present and specify how many matching tests are required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_number_of_tests
|
int
|
The minimum number of tests matching |
1
|
test_names
|
list[str]
|
List of test names to count. Generic tests are matched by |
required |
Receives at execution time:
| Name | Type | Description |
|---|---|---|
model |
ModelNode
|
The ModelNode object to check. |
tests |
list[TestNode]
|
List of TestNode objects parsed from |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | list[str] | None
|
Regex pattern(s) to match the model path. Model paths that match any pattern will not be checked. |
include |
str | list[str] | None
|
Regex pattern(s) to match the model path. Only model paths that match any pattern will be checked. |
materialization |
Literal[ephemeral, incremental, table, view] | None
|
Limit check to models with the specified materialization. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
Source code in src/dbt_bouncer/checks/manifest/models/tests.py
check_model_has_tests_by_type
#
Models must have at least the specified number of schema tests and data tests.
Rationale
dbt tests come in two flavours: schema tests (generic tests declared in .yml files, backed by test_metadata) and data tests (singular SQL files with no test_metadata). Teams sometimes mandate a minimum number of each type to ensure both broad coverage (via schema tests) and custom business-rule validation (via data tests). This check lets you enforce those minimums per-model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_number_of_data_tests
|
int
|
The minimum number of data (singular) tests a model must have. Default: 0. |
0
|
min_number_of_schema_tests
|
int
|
The minimum number of schema (generic) tests a model must have. Default: 0. |
0
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
model |
ModelNode
|
The ModelNode object to check. |
tests |
list[TestNode]
|
List of TestNode objects parsed from |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | list[str] | None
|
Regex pattern(s) to match the model path. Model paths that match any pattern will not be checked. |
include |
str | list[str] | None
|
Regex pattern(s) to match the model path. Only model paths that match any pattern will be checked. |
materialization |
Literal[ephemeral, incremental, table, view] | None
|
Limit check to models with the specified materialization. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
manifest_checks:
- name: check_model_has_tests_by_type
min_number_of_data_tests: 1
min_number_of_schema_tests: 2
Source code in src/dbt_bouncer/checks/manifest/models/tests.py
check_model_has_unique_test
#
Models must have a test for uniqueness of a column.
Rationale
A uniqueness test is the most fundamental data quality check — it ensures that the primary key or identifier column of a model does not contain duplicates, which would cause incorrect counts and fan-out in downstream joins. This check enforces that no model reaches production without at least one uniqueness assertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accepted_uniqueness_tests
|
list[str] | None
|
List of tests that are accepted as uniqueness tests. |
['dbt_expectations.expect_compound_columns_to_be_unique', 'dbt_utils.unique_combination_of_columns', 'unique']
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
model |
ModelNode
|
The ModelNode object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | list[str] | None
|
Regex pattern(s) to match the model path. Model paths that match any pattern will not be checked. |
include |
str | list[str] | None
|
Regex pattern(s) to match the model path. Only model paths that match any pattern will be checked. |
materialization |
Literal[ephemeral, incremental, table, view] | None
|
Limit check to models with the specified materialization. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
manifest_checks:
# Example of allowing a custom uniqueness test
- name: check_model_has_unique_test
accepted_uniqueness_tests:
- dbt_expectations.expect_compound_columns_to_be_unique # i.e. tests from packages must include package name
- my_custom_uniqueness_test
- unique
Source code in src/dbt_bouncer/checks/manifest/models/tests.py
check_model_has_unit_tests
#
Models must have more than the specified number of unit tests.
Rationale
Unit tests validate a model's transformation logic with controlled, mock inputs rather than real warehouse data. Requiring them on critical models (e.g. marts) ensures that complex SQL logic is verified independently of data volume or state, catching regressions before they affect downstream consumers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_number_of_unit_tests
|
int | None
|
The minimum number of unit tests that a model must have. |
1
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
manifest_obj |
ManifestObject
|
The ManifestObject object parsed from |
model |
ModelNode
|
The ModelNode object to check. |
unit_tests |
list[UnitTests]
|
List of UnitTests objects parsed from |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | list[str] | None
|
Regex pattern(s) to match the model path. Model paths that match any pattern will not be checked. |
include |
str | list[str] | None
|
Regex pattern(s) to match the model path. Only model paths that match any pattern will be checked. |
materialization |
Literal[ephemeral, incremental, table, view] | None
|
Limit check to models with the specified materialization. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Warning
This check is only supported for dbt 1.8.0 and above.
Example(s):
Source code in src/dbt_bouncer/checks/manifest/models/tests.py
check_model_test_coverage
#
Set the minimum percentage of models that have at least one test.
Rationale
Rather than requiring every model to be tested immediately, this check lets teams set a realistic coverage target and enforce it progressively. It prevents test coverage from silently declining as new, untested models are added to the project, creating a ratchet towards comprehensive testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_model_test_coverage_pct
|
float
|
The minimum percentage of models that must have at least one test. |
100
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
models |
list[ModelNode]
|
List of ModelNode objects parsed from |
tests |
list[TestNode]
|
List of TestNode objects parsed from |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):