can you test a single CTE as opposed to a model? For example, in:
# models/mymodel.sql
with my_cte as (
{%- set tables = dbt_utils.get_relations_by_pattern('my_schema%', 'prefix%') -%}
{%- set my_columns = ['my_col1', 'mycol2', 'mycol3',...,]
{{ dbt_utils.union_relations(relations = tables, include=my_columns ) }}
),
clean_cols as (
select
my_col1::numeric as mycol1,
coalesce(mycol2, mycol3) as my_coalesced_col23,
....
from my_cte
)
select * from clean_cols
I’d want to test that mycol2 and mycol3 are mutually exclusive (I have a custom generic test)
NOTE: I need those things to stay in the same file, otherwise it becomes very difficult to manage correctness with a long list of columns. Having the columns to include and select all in one place follows the best practice of rename and recast fields once and in one place.