dbt-labs / dbt-jsonschema

Apache License 2.0
109 stars 40 forks source link

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

Closed graciegoheen closed 4 months ago

graciegoheen commented 7 months ago

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).

joellabes commented 5 months ago

@graciegoheen I am working on this now!

Some questions/comments:

# 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 commented 5 months ago

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 commented 5 months ago

^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 commented 5 months ago

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 commented 5 months ago

@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 commented 4 months ago

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!