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

[unit testing] update "tests:" to "data_tests" #104

Closed
graciegoheen opened this issue Nov 28, 2023 · 6 comments · Fixed by #117
Closed

[unit testing] update "tests:" to "data_tests" #104

graciegoheen opened this issue Nov 28, 2023 · 6 comments · Fixed by #117

Comments

@graciegoheen
Copy link

graciegoheen commented Nov 28, 2023

With the introduction of unit testing (coming to dbt-core in 1.8), we are changing the prior tests: configs to data_tests: (though tests: with still be supported for backwards compatibility).

  • in schema yml update tests: to data_tests:
  • in dbt_project.yml update tests: to data_tests:
@joellabes
Copy link
Collaborator

@graciegoheen I am working on this now!

Some questions/comments:

  • If we're maintaining support for tests as well as data_tests, I don't think I want to do a rename so much as adding this as a second option. (This is easy to do)
  • Is it legal to have both a tests and a data_tests block?
# dbt_project.yml

tests: 
  joel_sandbox:
    marts:
      +enabled: false

data_tests:
  joel_sandbox:
    marts:
      +enabled: true

I assume not, and you're only allowed one of those?

@graciegoheen
Copy link
Author

I just tested this with:

version: 2

models:
  - name: dim_wizards
    columns:
      - name: wizard_id
        data_tests:
          - unique
          - not_null
  - name: fct_orders
    columns:
      - name: order_id
        tests:
          - unique
          - not_null

And that seems to have worked fine. When I ran dbt build, I get the warning:

[WARNING]: Deprecated functionality
The `tests` config has been renamed to `data_tests`. Please update your
`dbt_project.yml` configuration to reflect this change.

Otherwise, everything runs as expected:
Screenshot 2024-01-18 at 12 20 46 PM

@graciegoheen
Copy link
Author

^thinking that's sort of an odd deprecation notice, since in this case I used tests: in a schema.yml file not in dbt_project.yml

cc: @MichelleArk @gshank

@joellabes
Copy link
Collaborator

ty! That answers the first question, but my second q's example was in dbt_project.yml and was providing conflicting configs - what happens if you disable all the tests under the tests block and enable the same tests under the data_tests block? I assume something is going to explode and so the JSON Schema should only allow one or the other to exist

@graciegoheen
Copy link
Author

@joellabes Indeed!

Added this block to my dbt_project.yml file:

tests:
  +enabled: true

data_tests:
  +enabled: false

And got the handy-dandy error:
Screenshot 2024-01-24 at 9 46 46 AM

@joellabes
Copy link
Collaborator

Turns out it's not easy to have a "if a is defined, b is not allowed to be defined" rule :( so I think I'm going to have to leave this as a compile-time error. but good to know anyway!

@joellabes joellabes linked a pull request Feb 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants