Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore --empty in unit test ref/source calls #10764

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@


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 @@


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

Check warning on line 687 in core/dbt/context/providers.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/context/providers.py#L687

Added line #L687 was not covered by tests

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
Loading