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

[Core] How to add a description for custom generic tests #5631

Closed
dbeatty10 opened this issue Jun 9, 2024 · 3 comments · Fixed by #6940 or #6944
Closed

[Core] How to add a description for custom generic tests #5631

dbeatty10 opened this issue Jun 9, 2024 · 3 comments · Fixed by #6940 or #6944
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core size: medium This change will take up to a week to address

Comments

@dbeatty10
Copy link
Contributor

dbeatty10 commented Jun 9, 2024

Link to the page(s) on docs.getdbt.com requiring updates

https://docs.getdbt.com/best-practices/writing-custom-generic-tests

Tell us more about this update

There are two types of data tests, and users can create custom tests in both types:

  • generic
  • singular

When creating a custom generic test, many users want to add a description that shows up in the generated docs site.

One user described how to accomplish this goal: dbt-labs/dbt-core#2578 (comment)

e.g., do something like this:

macros/_generic_data_tests.yml or tests/generic/_generic_data_tests.yml (EDIT: the 2nd one didn't work for me)

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. It is deprecated as this functionality has been included in the custom implementation of `not_null`
    arguments:
      - name: model
        type: string
        description: Model Name
      - name: column_name
        type: string
        description: Column name that should not be an empty string

Note: it doesn't strictly need to be named _generic_data_tests.yml; it could be something else like properties.yml.

Reviewers/Stakeholders/SMEs

.

Related GitHub issues

Additional information

No response

@dbeatty10
Copy link
Contributor Author

@mirnawong1 I'm re-opening this because #6940 doesn't match the intent of this issue.

#6193 describes (3) totally different ways to add a description to data tests:

  1. Definitions of generic data tests
  2. Instances of generic data tests
  3. Instances of singular data tests

#6940 provides good examples of (2) 💡
But this issue is asking for an example of (1) 👈

What's the difference between a definition and an instance?

  • By "definition", I mean the Jinja macro that provides the code/logic for the data test (independent of that data test actually being used anywhere).
  • By "instance", I mean the YAML where the data test is actually added to a model/seed/etc.

So for (2), we'll want our docs to include an example of adding a description to the macro associated with the data test like this:

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. It is deprecated as this functionality has been included in the custom implementation of `not_null`
    arguments:
      - name: model
        type: string
        description: Model Name
      - name: column_name
        type: string
        description: Column name that should not be an empty string

👉 Note that the description here is under the macros: key.

@dbeatty10 dbeatty10 reopened this Feb 24, 2025
@mirnawong1
Copy link
Contributor

oh i see, its about the jinja macro! ok got it, thank you for clarifying!

@mirnawong1
Copy link
Contributor

hey @dbeatty10 ! ok i've created this pr #6944, which hopefully addresses this issue. mind having a look when you can? no rush of course

https://docs-getdbt-com-git-add-generic-test-macro-dbt-labs.vercel.app/best-practices/writing-custom-generic-tests#add-description-to-generic-data-test-logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core size: medium This change will take up to a week to address
Projects
None yet
3 participants