Niels van Beem
07/02/2025, 10:39 AMkapa.ai
07/02/2025, 10:39 AMkapa.ai
07/02/2025, 10:39 AMsql {% test empty_table(model) %} select 1 from {{ model }} limit 1 {% endtest %} To ensure this test only runs when an environment variable (e.g., envt) is set to acc, you can use dbt’s config with a where clause or conditionally include the test in your YAML using Jinja. For example, in your `schema.yml`: yaml models: - name: your_table tests: - empty_table: enabled: "{{ var('envt', 'dev') == 'acc' }}" This way, the test will only be enabled and executed when the environment variable envt is set to acc. This approach is supported by dbt and works with Elementary, as Elementary will pick up and alert on any dbt test, including custom ones, as long as they are enabled and executed in your environment [Table/view exists test](https://github.com/elementary-data/elementary/issues/1388), [Can elementary pick up if table is empty?](https://slack.com/archives/C02CTC89LAX/p1661744454211599). If you need to set the variable, you can do so when running dbt: bash dbt test --vars 'envt:acc' This ensures your test only triggers in the desired environment.