Skip to content

Commit

Permalink
Merge pull request #1 from oaknorthbank/meta-in-test
Browse files Browse the repository at this point in the history
Pull meta from config in test result logs
  • Loading branch information
tomwphillips authored Sep 24, 2024
2 parents 3ac20ce + 99355a6 commit 630ede0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/dbt/parser/schema_generic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def get_hashable_md(data: Union[str, int, float, List, Dict]) -> Union[str, List
"column_name": column_name,
"checksum": FileHash.empty().to_dict(omit_none=True),
"file_key_name": file_key_name,
"meta": target.config.get('meta', {}) if hasattr(target, 'config') else {},
}
try:
GenericTestNode.validate(dct)
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,30 @@ def test_node_info_on_results(self, project, logs_dir):
run_result_warning_count += 1

assert run_result_warning_count == 1


class TestRunResultMeta:
@pytest.fixture(scope="class")
def models(self):
model_config = """
models:
- name: my_model
meta:
owner: analytics
columns:
- name: id
tests:
- not_null
"""
return {"my_model.sql": "select null as id", "models.yml": model_config}

def test_test_failures_include_meta_from_model_config(self, project, logs_dir):
results = run_dbt(["--log-format=json", "build"], expect_pass=False)
assert len(results) == 2

log_file = read_file(logs_dir, "dbt.log")
messages = [json.loads(line) for line in log_file.split("\n") if line]
[
test_result,
] = [message for message in messages if message["info"]["name"] == "LogTestResult"]
assert test_result["data"]["node_info"]["meta"] == {"owner": "analytics"}

0 comments on commit 630ede0

Please sign in to comment.