From 096d43b857fa5dbad57f72215e84e4623740eba7 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 23 Sep 2024 20:19:18 +0100 Subject: [PATCH 1/3] ignore --empty in unit test ref/source calls --- core/dbt/context/providers.py | 10 ++++++++++ tests/functional/test_empty.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index 898437bf4da..bd5b0ac65f0 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -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, @@ -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, diff --git a/tests/functional/test_empty.py b/tests/functional/test_empty.py index d284fdcc3e5..053ef0fee0a 100644 --- a/tests/functional/test_empty.py +++ b/tests/functional/test_empty.py @@ -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: @@ -36,6 +44,28 @@ - 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") @@ -50,7 +80,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): From 154af211d40ecb5d3284877259503bd8ea96c759 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 23 Sep 2024 20:20:29 +0100 Subject: [PATCH 2/3] changelog entry --- .changes/unreleased/Fixes-20240923-202024.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240923-202024.yaml diff --git a/.changes/unreleased/Fixes-20240923-202024.yaml b/.changes/unreleased/Fixes-20240923-202024.yaml new file mode 100644 index 00000000000..2170773494c --- /dev/null +++ b/.changes/unreleased/Fixes-20240923-202024.yaml @@ -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" From 9f2316cb53c79a4403f4323c35837973417ea3e5 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 23 Sep 2024 23:09:41 +0100 Subject: [PATCH 3/3] linting --- tests/functional/test_empty.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/test_empty.py b/tests/functional/test_empty.py index 053ef0fee0a..7fa026a82eb 100644 --- a/tests/functional/test_empty.py +++ b/tests/functional/test_empty.py @@ -67,6 +67,7 @@ 2 """ + class TestEmptyFlag: @pytest.fixture(scope="class") def seeds(self):