From c98293b6bca5d968bbf1b82de9da12d68c87a90c Mon Sep 17 00:00:00 2001 From: devmessias Date: Mon, 11 Nov 2024 17:50:12 -0300 Subject: [PATCH] test(unit-test): capture compilation error --- .../unit_testing/test_unit_testing.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/functional/unit_testing/test_unit_testing.py b/tests/functional/unit_testing/test_unit_testing.py index 571affe16de..cd9083686da 100644 --- a/tests/functional/unit_testing/test_unit_testing.py +++ b/tests/functional/unit_testing/test_unit_testing.py @@ -309,7 +309,7 @@ def test_basic(self, project): assert len(results) == 2 -schema_ref_with_version = """ +schema_ref_with_versioned_model = """ models: - name: source latest_version: {latest_version} @@ -338,7 +338,7 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source')}}", "source.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 1, "input": "ref('source')"} ), } @@ -357,7 +357,7 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source')}}", "source_v1.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 1, "input": "ref('source', v=1)"} ), } @@ -376,7 +376,7 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source', v=1)}}", "source_v1.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 1, "input": "ref('source')"} ), } @@ -395,7 +395,7 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source')}}", "source_v1.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 2, "input": "ref('source')"} ), } @@ -414,16 +414,21 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source', v=2)}}", "source_v1.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 1, "input": "ref('source')"} ), } def test_basic(self, project): results = run_dbt(["run"]) + assert len(results) == 3 - # TODO: How to capture an compilation Error? pytest.raises(CompilationError) not working - run_dbt(["test", "--select", "model_to_test"], expect_pass=False) + # run_dbt(["test", "--select", "model_to_test"], expect_pass=False) + exec_result, _ = run_dbt_and_capture( + ["test", "--select", "model_to_test"], expect_pass=False + ) + msg_error = exec_result[0].message + assert msg_error.lower().lstrip().startswith("compilation error") class TestUnitTestRefWithVersionDiffLatest: @@ -433,7 +438,7 @@ def models(self): "model_to_test.sql": "select result from {{ ref('source', v=2)}}", "source_v1.sql": "select 2 as result", "source_v2.sql": "select 2 as result", - "schema.yml": schema_ref_with_version.format( + "schema.yml": schema_ref_with_versioned_model.format( **{"latest_version": 1, "input": "ref('source', v=2)"} ), }