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

[Stephen Girard] fix for on-run- hooks running in tests #1346

Merged
merged 1 commit into from
Mar 12, 2019
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
16 changes: 9 additions & 7 deletions core/dbt/task/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
class TestTask(RunTask):
"""
Testing:
1) Create tmp views w/ 0 rows to ensure all tables, schemas, and SQL
statements are valid
2) Read schema files and validate that constraints are satisfied
a) not null
b) uniquenss
c) referential integrity
d) accepted value
Read schema files + custom data tests and validate that
constraints are satisfied.
"""
def raise_on_first_error(self):
return False

def before_run(self, adapter, selected_uids):
# Don't execute on-run-* hooks for tests
self.populate_adapter_cache(adapter)

def after_run(self, adapter, results):
pass

def build_query(self):
query = {
"include": self.args.models,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{{ config(materialized='ephemeral') }}

select 1 as id
8 changes: 8 additions & 0 deletions test/integration/008_schema_tests_test/ephemeral/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

version: 2
models:
- name: ephemeral
columns:
- name: id
tests:
- unique
32 changes: 32 additions & 0 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ def test_malformed_schema_strict_will_break_run(self):
self.run_dbt(strict=True)


class TestHooksInTests(DBTIntegrationTest):

@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
# test ephemeral models so we don't need to do a run (which would fail)
return "test/integration/008_schema_tests_test/ephemeral"

@property
def project_config(self):
return {
"on-run-start": ["{{ exceptions.raise_compiler_error('hooks called in tests -- error') if execute }}"],
"on-run-end": ["{{ exceptions.raise_compiler_error('hooks called in tests -- error') if execute }}"],
}

@attr(type='postgres')
def test_hooks_dont_run_for_tests(self):
# This would fail if the hooks ran
results = self.run_dbt(['test', '--model', 'ephemeral'])
self.assertEqual(len(results), 1)
for result in results:
self.assertIsNone(result.error)
self.assertFalse(result.skipped)
# status = # of failing rows
self.assertEqual(
result.status, 0,
'test {} failed'.format(result.node.get('name'))
)

class TestCustomSchemaTests(DBTIntegrationTest):

def setUp(self):
Expand Down