[Feature] Unit tests should support being set as `enabled` or not
joellabes opened this issue · 4 comments
Is this your first time submitting a feature request?
- I have read the expectations for open source contributors
- I have searched the existing issues, and I could not find an existing issue for this feature
- I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
Describe the feature
Data tests can be disabled:
models:
- name: my_model
columns:
- name: my_column
tests:
- unique:
config:
enabled: false
But unit tests can't:
unit_tests:
- name: my_unit_test
...
config:
enabled: {{ target.type == 'bigquery' }} #doesn't work
I would like to be able to disable unit tests like every other node type in my project.
Describe alternatives you've considered
Michelle suggested using tags:
- name: my_unit_test
model: my_model
...
config:
tags: [bq_only]
and a command like dbt --target bigquery test -s test_type:unit --exclude tag:bq_only
which is, like, fine, but not as elegant.
Who will this benefit?
My specific use case is having unit tests for a dbt package to run in CI, but having some tests which should only run against a specific platform (e.g. unit testing BQ struct behaviour).
Are you interested in contributing this feature?
No response
Anything else?
No response
What do you think @graciegoheen ?
enabled
can be configured for all the other resource types that I tried out:
- models
- seeds
- snapshots
- sources
- exposures
- semantic models
- generic data tests
- singular data tests
- analyses
resource type | dbt_project.yml |
properties YAML | config() macro |
---|---|---|---|
models | ✅ | ✅ | ✅ |
snapshots | ✅ | ✅ | ✅ |
seeds | ✅ | ✅ | ❌ |
sources | ✅ | ✅ | ❌ |
exposures | ✅ | ✅ | ❌ |
semantic models | ✅ | ✅ | ❌ |
analyses | ❌ | ✅ | ✅ |
singular data tests | ✅ | ❌ | ✅ |
generic data tests | ✅ | ✅ | ❌ |
unit tests | ❌ | ❌ | ❌ |
Example files
models/metricflow_time_spine.sql
{{ config(materialized='table') }}
select cast({{ dbt.string_literal("2000-01-01") }} as date) as date_day
Note: singular data tests can't be disabled within a YAML file (like models/_properties.yml
, but either dbt_project.yml
or config()
within SQL file are options.
tests/singular_data_test.sql
-- { { config(enabled=false) }}
select *
from {{ ref('metricflow_time_spine' )}}
where 0=1
snapshots/my_snapshot.sql
{% snapshot my_snapshot %}
{{
config(
target_database=target.database,
target_schema=target.schema,
unique_key='id',
strategy='check',
check_cols='all',
)
}}
select 1 as id
{% endsnapshot %}
seeds/my_seed.csv
id
1
Note: analyses can't be selectively disabled within dbt_project.yml
-- they inherit the config from models
within dbt_project.yml
.
analyses/my_analysis.sql
-- { { config(enabled=false) }}
select 1 as id
models/_properties.yml
models:
- name: metricflow_time_spine
config:
enabled: true
columns:
- name: date_day
data_tests:
- not_null:
name: generic_data_test
config:
enabled: true
sources:
- name: my_source
tables:
- name: my_source_table
config:
enabled: true
seeds:
- name: my_seed
config:
enabled: true
snapshots:
- name: my_snapshot
config:
enabled: true
analyses:
- name: my_analysis
config:
enabled: true
exposures:
- name: my_exposure
type: dashboard
owner:
email: exposure_owner@my_company.com
config:
enabled: true
metrics:
- name: my_metric
label: my_metric
type: derived
type_params:
expr: revenue - cost
config:
enabled: true
semantic_models:
- name: my_semantic_model
model: ref('metricflow_time_spine')
config:
enabled: true
saved_queries:
- name: my_saved_query
query_params:
metrics:
- my_metric
config:
enabled: true
unit_tests:
- name: my_unit_test
given: []
model: metricflow_time_spine
expect:
rows:
- {date_day: 2000-01-01}
# Note: this does NOT have any effect
# So need to comment out or delete this unit test if its associated model(s) are disabled
config:
enabled: true
dbt_project.yml
name: "my_project"
# Note: also disables analyses!
models:
my_project:
+enabled: true
seeds:
my_project:
+enabled: true
snapshots:
my_project:
+enabled: true
sources:
my_project:
+enabled: true
exposures:
my_project:
+enabled: true
metrics:
my_project:
+enabled: true
# Note: inconsistent to have "semantic-models" with a dash, but "data_tests" and "unit_tests" with underscores
semantic-models:
my_project:
+enabled: true
# Note: this has no effect -- must configure within properties.yml or config() within the analysis file
analyses:
my_project:
+enabled: true
data_tests:
my_project:
+enabled: true
# This has no effect -- there is no way to disable a unit test outside of commenting it out or excluding it from the selection.
# It will give the following warning:
# [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
# There are 1 unused configuration paths:
# - unit_tests.my_project
unit_tests:
my_project:
+enabled: true
Run this command to see which resources are enabled:
dbt list --resource-type all
Then change the enabled
config for one or more resources and re-run the dbt list
command above to see if it disappears or not.
We actually already have an issue for this -> #9109
oops my bad 😬 ty both!