@@ -7,8 +7,8 @@ This dbt package contains macros to assert test and documentation coverage from
7
7
## Table of Contents
8
8
- [ Install] ( #install )
9
9
- [ Configurations] ( #configurations )
10
- - [ ** Required Tests** ] ( #required-tests )
11
- - [ ** Required Docs** ] ( #required-docs )
10
+ - [ Required Tests] ( #required-tests )
11
+ - [ Required Docs] ( #required-docs )
12
12
- [ Usage] ( #usage )
13
13
- [ required_tests (source)] ( #required_tests-source )
14
14
- [ required_docs (source)] ( #required_docs-source )
@@ -22,7 +22,7 @@ Include in `packages.yml`:
22
22
``` yaml
23
23
packages :
24
24
- package : tnightengale/dbt_meta_testing
25
- version : 0.2.1
25
+ version : 0.3.0
26
26
` ` `
27
27
For latest release, see
28
28
https://github.com/tnightengale/dbt-meta-testing/releases.
@@ -33,44 +33,59 @@ This package features two meta configs that can be applied to a dbt project:
33
33
[here](https://docs.getdbt.com/reference/model-configs) to learn more about
34
34
model configurations in dbt.
35
35
36
- # ## ** Required Tests**
36
+ # ## Required Tests
37
37
To require test coverage, define the `+required_tests` configuration on a model
38
38
path in `dbt_project.yml` :
39
39
` ` ` yaml
40
40
# dbt_project.yml
41
41
...
42
42
models:
43
- project:
44
- staging:
45
- +required_tests: {"unique": 1, "not_null": 1}
46
- marts:
47
- +required_tests: {"unique": 1}
43
+ project:
44
+ +required_docs: true
45
+ marts:
46
+ +required_tests: {"unique.*|not_null": 1}
47
+ model_2:
48
+ +required_tests:
49
+ "mocker.*|unique": 1
50
+ "mock_schema_test": 1
51
+ ".*data_test": 1
48
52
` ` `
49
53
50
- The `+required_tests` config must be either a `dict` or `None`. All the regular
54
+ The `+required_tests` config must be `None` or a `dict` with `str` keys and `int`
55
+ values. YAML dictionaries are accepted.
56
+
57
+ All the regular
51
58
dbt configuration hierarchy rules apply. For example, individual model configs
52
59
will override configs from the `dbt_project.yml` :
53
60
` ` ` sql
54
- -- /models/marts/core/your_model.sql
55
- {{
56
- config(required_tests=None)
57
- }}
61
+ # /models/marts/core/your_model.sql
62
+
63
+ -- This overrides the config in dbt_project.yml, and this model will not require tests
64
+ {{ config(required_tests=None) }}
58
65
59
66
SELECT
60
67
...
61
68
` ` `
62
- The provided dictionary can contain any column schema test as a key, followed by
63
- the minimum number of occurances which must be included on the model. In the
64
- example above, every model in the `models/marts/` path must include at least one
65
- ` unique` test.
66
-
67
- Custom column-level schema tests are supported. However, in order to appear in
68
- the `graph` context variable (which this package parses), they must be applied
69
- to at least one model in the project prior to compilation.
70
-
71
- Model-level schema tests are currently _not supported_. For example the
72
- following model-level `dbt_utils.equal_rowcount` test _cannot_ currently be
73
- asserted via the configuration :
69
+ > **_New in Version 0.3.0_**
70
+
71
+ The keys of the config are evaluated against both data and schema tests
72
+ (including any custom tests) using the
73
+ [re.match](https://docs.python.org/3/library/re.html#re.match) function.
74
+
75
+ Therefore, any test restriction which can be expressed in regex can be
76
+ evaluated.
77
+
78
+ For example, in the `dbt_project.yml` above, the path configuration on the `marts` model path
79
+ requires each model in that path to have at least one test that either _starts
80
+ with_ `unique` **or** is an _exact match_ for the `not_null` test.
81
+
82
+ Schema tests are matched against their common names, (eg. `not_null`,
83
+ ` accepted_values` ).
84
+
85
+ Data tests are matched against their macro name.
86
+
87
+ Custom schema tests are matched against their name, without the `test_` prefix, eg. `mock_schema_test` :
88
+
74
89
` ` ` yaml
75
90
# models/schema.yml
76
91
...
@@ -88,7 +103,8 @@ asserted via the configuration:
88
103
- mock_schema_test
89
104
` ` `
90
105
91
- Models that do not meet their configured test minimums will be listed in the
106
+ Models that do not meet their configured test minimums, because they either lack
107
+ the tests or are not documented, will be listed in the
92
108
error when validated via a `run-operation` :
93
109
` ` `
94
110
usr@home dbt-meta-testing $ dbt run-operation required_tests
@@ -104,7 +120,7 @@ Encountered an error while running operation: Compilation Error in macro require
104
120
usr@home dbt-meta-testing $
105
121
` ` `
106
122
107
- # ## ** Required Docs**
123
+ # ## Required Docs
108
124
To require documentation coverage, define the `+required_docs` configuration on
109
125
a model path in `dbt_project.yml` :
110
126
` ` ` yaml
@@ -114,7 +130,9 @@ models:
114
130
project:
115
131
+required_docs: true
116
132
` ` `
117
- The `+required_docs` config must be a `bool`. It also **does not check ephemeral
133
+ The `+required_docs` config must be a `bool`.
134
+
135
+ It also **does not check ephemeral
118
136
models**. This is because it cannot leverage `adapter.get_columns_in_relation()`
119
137
macro on ephemeral models, which it uses to fetch columns from the data
120
138
warehouse and detect columns without documentation.
0 commit comments