Print the compiled test query for failing tests.

In short:
Is there a way to, after tests have ran, print the compiled test sql queries for the failing tests?

We have many tests for datatypes, unique-combination-of-columns and not-nulls for example.
To know which tests failed we now check either

  1. a databricks dashboard thats based on dbt-artifacts tables
  2. the stdout of the databricks workflow we use

The compiled test query does not seem to be included in dbt-artifacts tables (correct me if I am wrong!?) (although we have the variable dbt_artifacts_exclude_all_results: true, but it would be kind of overkill to include it just for this I guess)
And the path to the compiled test query is printed, but the query itself is not. The query is the exact thing that is necessary to start your debugging.

Is there a way to print that compiled query?

Things I considered:

  • running a python on-run-end hook… just failed, I dont know how other people succeed, but I could not find a way to run a python script from the dbt hooks… And IF that works, would there be sufficient context available to determine a failed test and get it’s compiled query?
  • Considering “store_failures”, yes, is probably a nice alternative, although having the actual test query is more helpful I believe, since that is the query you need for debugging.

Many thanks in advance!

For test analysis, I can suggest two alternatives:

  1. Use “elementary-data”
  2. Create a custom macro to store the value from “run_results.json” of each execution, containing the test status and script compile.

If this doesn’t help and you need a clearer example, I’m available to assist.

1 Like