dbt-meta-testing icon indicating copy to clipboard operation
dbt-meta-testing copied to clipboard

Allow testing of test names, rather than just test type

Open ciejer opened this issue 3 years ago • 3 comments
trafficstars

This project is awesome! I'm looking for something that can validate that specific fields have specific tests (every model in a folder must have a not_null test on their load_date_time column).

A proposed implementation might be a prefix:
+required_tests: {"testname!not_null.*load_date_time": 1}
This would require returning an object array rather than string array from tests_per_model ([{name: not_null_tablename_load_date_time, type: not_null}, ...], and adding a case statement to get_regex_match_count to split off and truncate the testname! - but would allow far more flexibility in future.

I'm happy to contribute with my mediocre python skills if you like the implementation.

ciejer avatar Jan 04 '22 21:01 ciejer

@ciejer Sorry for the long delay, life has been busy!

Yes I really like this idea! I think we'll need to implement another category of meta assertion though: +required_columns, to first check if the column is present, and then I'm thinking take some intersection of those requirements to assert that a column is present AND has the specified tests.

I can look into this in early Feb and get back to you with my thought on implementation, unless you've already forked and got something working :) In which case, I am happy to accept contributions!

tnightengale avatar Jan 25 '22 15:01 tnightengale

Thanks for the reply @tnightengale! - I've been swamped myself, so no worries about the delay. I'll be moving on from my current team shortly, but will be leaving a note on our ticket to check here when they get to revisiting our test coverage.

Thanks again -Chris

ciejer avatar Jan 26 '22 00:01 ciejer

Just looking over the issues list here... One possibility for this might be to piggyback on dbt-expectations? There are some tests already like this: https://github.com/calogica/dbt-expectations#expect_column_to_exist and https://github.com/calogica/dbt-expectations#expect_table_columns_to_contain_set

codigo-ergo-sum avatar Feb 15 '22 22:02 codigo-ergo-sum