Conditionally running dbt tests / Only running dbt tests in production

If your tests are purely data tests, you can toggle them using a dbt var or environment variable. We’ve used env vars to enable/disable models more easily, and it works for tests too.

-- tests/t_example.sql
{{
  config(
    enabled=not env_var('DISABLE_RECENCY_CHECK', ''),
  )
}}

SELECT 1

and then compare: DISABLE_RECENCY_CHECK=1 dbt test --model t_example vs. dbt test --model t_example.

1 Like