I have a bunch of dbt models that share about 90% of their structure. The idea is that these models will be combined into a single unified downstream model during the dbt run. Currently my tests for the models have a lot of duplication. For example
- name: model1
columns:
- name: colA
tests:
- accepted_values:
- values ['a','b']
- name: colB
tests:
- non_null
- name: model2
columns:
- name: colA
tests:
- accepted_values:
- values ['a','b','c']
- name: colB
tests:
- non_null
I'd like to reduce the duplication in schema.yml file by re-using the test config with small variations.
What I have tried so far
defining the tests as a var in
dbt_project.ymland referencing it in theschema.yml. This works but you cannot have any variationdefining a macro that returns a python list that has the test config and calling the macro like this
columns: "{{ common_tests() }}"
This doesn't work as I get could not render {{ common_tests() }} 'common_tests' is undefined.
Interestingly it is possible to render yaml with a macro within individual tests within the yaml file, just not at the top level.
I feel there should be an easy(ish) solution here, I'm just not finding it. Thanks in advance.