You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/reference/resource-properties/description.md
+154-3Lines changed: 154 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ description: "This guide explains how to use the description key to add YAML des
14
14
{ label: 'Analyses', value: 'analyses', },
15
15
{ label: 'Macros', value: 'macros', },
16
16
{ label: 'Data tests', value: 'data_tests', },
17
+
{ label: 'Unit tests', value: 'unit_tests', },
17
18
]
18
19
}>
19
20
<TabItemvalue="models">
@@ -150,24 +151,81 @@ macros:
150
151
151
152
<VersionBlockfirstVersion="1.9">
152
153
154
+
You can add a description to a [singular data test](/docs/build/data-tests#singular-data-tests) or a [generic data test](/docs/build/data-tests#generic-data-tests).
155
+
153
156
<Filename='tests/schema.yml'>
154
157
155
158
```yml
159
+
# Singular data test example
160
+
156
161
version: 2
157
162
158
163
data_tests:
159
164
- name: data_test_name
160
165
description: markdown_string
161
-
162
166
```
167
+
</File>
168
+
169
+
<File name='tests/schema.yml'>
170
+
171
+
```yml
172
+
# Generic data test example
173
+
174
+
version: 2
163
175
176
+
models:
177
+
- name: model_name
178
+
columns:
179
+
- name: column_name
180
+
tests:
181
+
- unique:
182
+
description: markdown_string
183
+
```
164
184
</File>
165
185
166
186
</VersionBlock>
167
187
168
188
<VersionBlock lastVersion="1.8">
169
189
170
-
The `description` property is available for generic and singular data tests beginning in dbt v1.9.
190
+
The `description` property is available for [singular data tests](/docs/build/data-tests#singular-data-tests) or [generic data tests](/docs/build/data-tests#generic-data-tests) beginning in dbt v1.9.
191
+
192
+
</VersionBlock>
193
+
194
+
</TabItem>
195
+
196
+
<TabItem value="unit_tests">
197
+
198
+
<VersionBlock firstVersion="1.8">
199
+
200
+
<File name='models/schema.yml'>
201
+
202
+
```yml
203
+
unit_tests:
204
+
- name: unit_test_name
205
+
description: "markdown_string"
206
+
model: model_name
207
+
given: ts
208
+
- input: ref_or_source_call
209
+
rows:
210
+
- {column_name: column_value}
211
+
- {column_name: column_value}
212
+
- {column_name: column_value}
213
+
- {column_name: column_value}
214
+
- input: ref_or_source_call
215
+
format: csv
216
+
rows: dictionary | string
217
+
expect:
218
+
format: dict | csv | sql
219
+
fixture: fixture_name
220
+
```
221
+
222
+
</File>
223
+
224
+
</VersionBlock>
225
+
226
+
<VersionBlock lastVersion="1.7">
227
+
228
+
The `description` property is available for [unit tests](/docs/build/unit-tests) beginning in dbt v1.8.
171
229
172
230
</VersionBlock>
173
231
@@ -176,13 +234,17 @@ The `description` property is available for generic and singular data tests begi
176
234
</Tabs>
177
235
178
236
## Definition
179
-
A user-defined description. Can be used to document:
237
+
238
+
A user-defined description used to document:
239
+
180
240
- a model, and model columns
181
241
- sources, source tables, and source columns
182
242
- seeds, and seed columns
183
243
- snapshots, and snapshot columns
184
244
- analyses, and analysis columns
185
245
- macros, and macro arguments
246
+
- data tests, and data test columns
247
+
- unit tests for models
186
248
187
249
These descriptions are used in the documentation website rendered by dbt (refer to [the documentation guide](/docs/build/documentation) or [dbt Explorer](/docs/collaborate/explore-projects)).
188
250
@@ -196,6 +258,18 @@ Be mindful of YAML semantics when providing a description. If your description c
196
258
197
259
## Examples
198
260
261
+
This section contains examples of how to add descriptions to various resources:
262
+
263
+
- [Add a simple description to a model and column](#add-a-simple-description-to-a-model-and-column) <br />
264
+
- [Add a multiline description to a model](#add-a-multiline-description-to-a-model) <br />
265
+
- [Use some markdown in a description](#use-some-markdown-in-a-description) <br />
266
+
- [Use a docs block in a description](#use-a-docs-block-in-a-description) <br />
267
+
- [Link to another model in a description](#link-to-another-model-in-a-description)
268
+
- [Include an image from your repo in your descriptions](#include-an-image-from-your-repo-in-your-descriptions) <br />
269
+
- [Include an image from the web in your descriptions](#include-an-image-from-the-web-in-your-descriptions) <br />
270
+
- [Add a description to a data test](#add-a-description-to-a-data-test) <br />
271
+
- [Add a description to a unit test](#add-a-description-to-a-unit-test) <br />
272
+
199
273
### Add a simple description to a model and column
200
274
201
275
<File name='models/schema.yml'>
@@ -400,3 +474,80 @@ models:
400
474
401
475
If mixing images and text, also consider using a docs block.
402
476
477
+
### Add a description to a data test
478
+
479
+
<VersionBlock lastVersion="1.8">
480
+
481
+
<VersionCallout version="1.9" />
482
+
483
+
</VersionBlock>
484
+
485
+
You can add a `description` property to a generic or singular data test.
486
+
487
+
#### Generic data test
488
+
489
+
This example shows a generic data test that checks for unique values in a column for the `orders` model.
490
+
491
+
<File name='models/<filename>.yml'>
492
+
493
+
```yaml
494
+
version: 2
495
+
496
+
models:
497
+
- name: orders
498
+
columns:
499
+
- name: order_id
500
+
tests:
501
+
- unique:
502
+
description: "The order_id is unique for every row in the orders model"
503
+
```
504
+
</File>
505
+
506
+
#### Singular data test
507
+
508
+
This example shows a singular data test that checks to ensure all values in the `payments` model are not negative (≥ 0).
509
+
510
+
<File name='tests/<filename>.yml'>
511
+
512
+
```yaml
513
+
version: 2
514
+
data_tests:
515
+
- name: assert_total_payment_amount_is_positive
516
+
description: >
517
+
Refunds have a negative amount, so the total amount should always be >= 0.
518
+
Therefore return records where total amount < 0 to make the test fail.
519
+
520
+
```
521
+
</File>
522
+
523
+
Note that in order for the test to run, the `tests/assert_total_payment_amount_is_positive.sql` SQL file has to exist in the `tests` directory.
524
+
525
+
### Add a description to a unit test
526
+
527
+
<VersionBlock lastVersion="1.7">
528
+
529
+
<VersionCallout version="1.8" />
530
+
531
+
</VersionBlock>
532
+
533
+
This example shows a unit test that checks to ensure the `opened_at` timestamp is properly truncated to a date for the `stg_locations` model.
0 commit comments