Skip to content

Commit

Permalink
ignore --empty in unit test ref/source calls (#10764)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 23, 2024
1 parent 46da967 commit aa23af9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240923-202024.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Ignore --empty in unit test ref/source rendering
time: 2024-09-23T20:20:24.151285+01:00
custom:
Author: michelleark
Issue: "10516"
10 changes: 10 additions & 0 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ def create_relation(self, target_model: ManifestNode) -> RelationProxy:


class RuntimeUnitTestRefResolver(RuntimeRefResolver):
@property
def resolve_limit(self) -> Optional[int]:
# Unit tests should never respect --empty flag or provide a limit since they are based on fake data.
return None

def resolve(
self,
target_name: str,
Expand Down Expand Up @@ -676,6 +681,11 @@ def resolve(self, source_name: str, table_name: str):


class RuntimeUnitTestSourceResolver(BaseSourceResolver):
@property
def resolve_limit(self) -> Optional[int]:
# Unit tests should never respect --empty flag or provide a limit since they are based on fake data.
return None

def resolve(self, source_name: str, table_name: str):
target_source = self.manifest.resolve_source(
source_name,
Expand Down
33 changes: 33 additions & 0 deletions tests/functional/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
from {{ source('seed_sources', 'raw_source') }}
"""

model_no_ephemeral_ref_sql = """
select *
from {{ ref('model_input') }}
union all
select *
from {{ source('seed_sources', 'raw_source') }}
"""


schema_sources_yml = """
sources:
Expand All @@ -36,6 +44,29 @@
- name: raw_source
"""

unit_tests_yml = """
unit_tests:
- name: test_my_model
model: model_no_ephemeral_ref
given:
- input: ref('model_input')
format: csv
rows: |
id
1
- input: source('seed_sources', 'raw_source')
format: csv
rows: |
id
2
expect:
format: csv
rows: |
id
1
2
"""


class TestEmptyFlag:
@pytest.fixture(scope="class")
Expand All @@ -50,7 +81,9 @@ def models(self):
"model_input.sql": model_input_sql,
"ephemeral_model_input.sql": ephemeral_model_input_sql,
"model.sql": model_sql,
"model_no_ephemeral_ref.sql": model_no_ephemeral_ref_sql,
"sources.yml": schema_sources_yml,
"unit_tests.yml": unit_tests_yml,
}

def assert_row_count(self, project, relation_name: str, expected_row_count: int):
Expand Down

0 comments on commit aa23af9

Please sign in to comment.