Skip to content

Commit

Permalink
test(unit-test): capture compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
devmessias committed Nov 11, 2024
1 parent ba528e9 commit c98293b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/functional/unit_testing/test_unit_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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')"}
),
}
Expand All @@ -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)"}
),
}
Expand All @@ -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')"}
),
}
Expand All @@ -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')"}
),
}
Expand All @@ -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:
Expand All @@ -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)"}
),
}
Expand Down

0 comments on commit c98293b

Please sign in to comment.