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

Use SchemaParser render context to render test configs #3646

Merged
merged 3 commits into from
Jul 29, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Partial parsing: fix error after changing empty yaml file ([#3567](https://github.com/dbt-labs/dbt/issues/3567), [#3618](https://github.com/dbt-labs/dbt/pull/3618))
- Partial parsing: handle source tests when changing test macro ([#3584](https://github.com/dbt-labs/dbt/issues/3584), [#3620](https://github.com/dbt-labs/dbt/pull/3620))
- Partial parsing: schedule new macro file for parsing when macro patching ([#3627](https://github.com/dbt-labs/dbt/issues/3627), [#3627](https://github.com/dbt-labs/dbt/pull/3627))
- Use `SchemaParser`'s render context to render test configs in order to support `var()` configured at the project level and passed in from the cli ([#3564](https://github.com/dbt-labs/dbt/issues/3564). [#3646](https://github.com/dbt-labs/dbt/pull/3646))

### Under the hood
- Improve default view and table materialization performance by checking relational cache before attempting to drop temp relations ([#3112](https://github.com/fishtown-analytics/dbt/issues/3112), [#3468](https://github.com/fishtown-analytics/dbt/pull/3468))
Expand Down
12 changes: 4 additions & 8 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ def __init__(
self.project.config_version == 2
)
if all_v_2:
ctx = generate_schema_yml(
self.render_ctx = generate_schema_yml(
self.root_project, self.project.project_name
)
else:
ctx = generate_target_context(
self.render_ctx = generate_target_context(
self.root_project, self.root_project.cli_vars
)

self.raw_renderer = SchemaYamlRenderer(ctx)
self.raw_renderer = SchemaYamlRenderer(self.render_ctx)

internal_package_names = get_adapter_package_names(
self.root_project.credentials.type
Expand Down Expand Up @@ -287,17 +287,13 @@ def _parse_generic_test(
tags: List[str],
column_name: Optional[str],
) -> ParsedSchemaTestNode:

render_ctx = generate_target_context(
self.root_project, self.root_project.cli_vars
)
try:
builder = TestBuilder(
test=test,
target=target,
column_name=column_name,
package_name=target.package_name,
render_ctx=render_ctx,
render_ctx=self.render_ctx,
)
except CompilationException as exc:
context = _trimmed(str(target))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

models:
- name: model
tests:
- equivalent:
value: "{{ var('myvar', 'baz') }}-bar"
30 changes: 28 additions & 2 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ def test_postgres_quote_required_column(self):
self.assertEqual(len(results), 2)


class TestVarsSchemaTests(DBTIntegrationTest):
class TestCliVarsSchemaTests(DBTIntegrationTest):
@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "models-v2/render_test_arg_models"
return "models-v2/render_test_cli_arg_models"

@property
def project_config(self):
Expand All @@ -356,6 +356,32 @@ def test_postgres_argument_rendering(self):
self.run_dbt(['test'], expect_pass=False)


class TestConfiguredVarsSchemaTests(DBTIntegrationTest):
@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "models-v2/render_test_configured_arg_models"

@property
def project_config(self):
return {
'config-version': 2,
"macro-paths": ["macros-v2/macros"],
'vars': {
'myvar': 'foo'
}
}

@use_profile('postgres')
def test_postgres_argument_rendering(self):
results = self.run_dbt()
self.assertEqual(len(results), 1)
results = self.run_dbt(['test'])
self.assertEqual(len(results), 1)

class TestSchemaCaseInsensitive(DBTIntegrationTest):
@property
def schema(self):
Expand Down