Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds description example of core logic for generic test #6944

Merged
merged 16 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions website/docs/best-practices/custom-generic-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ models:

With one line of code, you've just created a test! In this example, `users` will be passed to the `is_even` test as the `model` argument, and `favorite_number` will be passed in as the `column_name` argument. You could add the same line for other columns, other models—each will add a new test to your project, _using the same generic test definition_.

### Add description to generic data test logic

You can add a description to the Jinja macro that provides the core logic for a data test by including the `description` key under the `macros:` section. You can add descriptions directly to the macro, including descriptions for macro arguments.

Here's an example:

<File name="macros/generic/schema.yml">

```yaml
macros:
- name: test_not_empty_string
description: Complementary test to default `not_null` test as it checks that there is not an empty string. It only accepts columns of type string.
arguments:
- name: model
type: string
description: Model Name
- name: column_name
type: string
description: Column name that should not be an empty string
```
</File>

In this example:
- When documenting custom test macros in a `schema.yml` file, add the `test_` prefix to the macro name. For example, if the test block's name is `not_empty_string`, then the macro's name would be `test_not_empty_string`.
- We've provided a description at the macro level, explaining what the test does and any relevant notes.
- Each argument (like `model`, `column_name`) also includes a description to clarify its purpose.

### Generic tests with additional arguments

Expand Down
2 changes: 1 addition & 1 deletion website/docs/docs/build/data-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ In plain English, these data tests translate to:

Behind the scenes, dbt constructs a `select` query for each data test, using the parametrized query from the generic test block. These queries return the rows where your assertion is _not_ true; if the test returns zero rows, your assertion passes.

You can find more information about these data tests, and additional configurations (including [`severity`](/reference/resource-configs/severity) and [`tags`](/reference/resource-configs/tags)) in the [reference section](/reference/resource-properties/data-tests).
You can find more information about these data tests, and additional configurations (including [`severity`](/reference/resource-configs/severity) and [`tags`](/reference/resource-configs/tags)) in the [reference section](/reference/resource-properties/data-tests). You can also add descriptions to the Jinja macro that provides the core logic of a generic data test. Refer to the [Add description to generic data test logic](/best-practices/writing-custom-generic-tests#add-description-to-generic-data-test-logic) for more information.

### More generic data tests

Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/data-test-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ models:
```
</File>

You can also add descriptions to the Jinja macro that provides the core logic of a generic data test. Refer to the [Add description to generic data test logic](/best-practices/writing-custom-generic-tests#add-description-to-generic-data-test-logic) for more information.

For a singular test, define it in the test's directory:

<File name='tests/my_custom_test.yml'>
Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/resource-properties/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ models:
```
</File>

You can also add descriptions to the Jinja macro that provides the core logic of a generic data test. Refer to the [Add description to generic data test logic](/best-practices/writing-custom-generic-tests#add-description-to-generic-data-test-logic) for more information.

#### Singular data test

This example shows a singular data test that checks to ensure all values in the `payments` model are not negative (≥ 0).
Expand Down
Loading