From 64b4d3f95d6bbcf5b2a67b7fd9d921041b9200ab Mon Sep 17 00:00:00 2001 From: Kyle Wigley Date: Fri, 21 May 2021 12:01:39 -0400 Subject: [PATCH] add failures field --- core/dbt/contracts/results.py | 6 +----- core/dbt/task/base.py | 8 +++++--- core/dbt/task/printer.py | 8 ++++---- core/dbt/task/run.py | 3 ++- core/dbt/task/test.py | 10 ++++------ 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/core/dbt/contracts/results.py b/core/dbt/contracts/results.py index 7076fea29fb..9a276699ae3 100644 --- a/core/dbt/contracts/results.py +++ b/core/dbt/contracts/results.py @@ -116,17 +116,13 @@ class RunResult(NodeResult): 'serialize': lambda x: None, 'deserialize': lambda x: None } ) + failures: Optional[int] = None @property def skipped(self): return self.status == RunStatus.Skipped -@dataclass -class TestResult(RunResult): - failures: int = 0 - - @dataclass class ExecutionResult(dbtClassMixin): results: Sequence[BaseResult] diff --git a/core/dbt/task/base.py b/core/dbt/task/base.py index 0da36feb294..d3e206ef3de 100644 --- a/core/dbt/task/base.py +++ b/core/dbt/task/base.py @@ -214,7 +214,7 @@ def run_with_hooks(self, manifest): return result def _build_run_result(self, node, start_time, status, timing_info, message, - agate_table=None, adapter_response=None): + agate_table=None, adapter_response=None, failures=None): execution_time = time.time() - start_time thread_id = threading.current_thread().name if adapter_response is None: @@ -227,7 +227,8 @@ def _build_run_result(self, node, start_time, status, timing_info, message, message=message, node=node, agate_table=agate_table, - adapter_response=adapter_response + adapter_response=adapter_response, + failures=failures ) def error_result(self, node, message, start_time, timing_info): @@ -256,7 +257,8 @@ def from_run_result(self, result, start_time, timing_info): timing_info=timing_info, message=result.message, agate_table=result.agate_table, - adapter_response=result.adapter_response + adapter_response=result.adapter_response, + failures=result.failures ) def skip_result(self, node, message): diff --git a/core/dbt/task/printer.py b/core/dbt/task/printer.py index 82cc27d5902..d4a94410301 100644 --- a/core/dbt/task/printer.py +++ b/core/dbt/task/printer.py @@ -12,7 +12,7 @@ from dbt import utils from dbt.contracts.results import ( - FreshnessStatus, NodeResult, NodeStatus, TestStatus + FreshnessStatus, NodeStatus, TestStatus ) @@ -115,7 +115,7 @@ def get_printable_result( def print_test_result_line( - result: NodeResult, schema_name, index: int, total: int + result, index: int, total: int ) -> None: model = result.node @@ -128,11 +128,11 @@ def print_test_result_line( color = ui.green logger_fn = logger.info elif result.status == TestStatus.Warn: - info = 'WARN' + info = f'WARN {result.failures}' color = ui.yellow logger_fn = logger.warning elif result.status == TestStatus.Fail: - info = 'FAIL' + info = f'FAIL {result.failures}' color = ui.red logger_fn = logger.error else: diff --git a/core/dbt/task/run.py b/core/dbt/task/run.py index e397551cd8f..8469d849e07 100644 --- a/core/dbt/task/run.py +++ b/core/dbt/task/run.py @@ -201,7 +201,8 @@ def _build_run_model_result(self, model, context): thread_id=threading.current_thread().name, execution_time=0, message=str(result.response), - adapter_response=adapter_response + adapter_response=adapter_response, + failures=result.get('failures') ) def _materialization_relations( diff --git a/core/dbt/task/test.py b/core/dbt/task/test.py index c5b5bc342c9..25b560a893a 100644 --- a/core/dbt/task/test.py +++ b/core/dbt/task/test.py @@ -14,7 +14,7 @@ CompiledTestNode, ) from dbt.contracts.graph.manifest import Manifest -from dbt.contracts.results import TestResult, TestStatus, PrimitiveDict +from dbt.contracts.results import TestStatus, PrimitiveDict, RunResult from dbt.context.providers import generate_runtime_model from dbt.clients.jinja import MacroGenerator from dbt.exceptions import ( @@ -43,9 +43,7 @@ def describe_node(self): return "test {}".format(node_name) def print_result_line(self, result): - schema_name = self.node.schema - print_test_result_line(result, schema_name, self.node_index, - self.num_nodes) + print_test_result_line(result, self.node_index, self.num_nodes) def print_start_line(self): description = self.describe_node() @@ -132,14 +130,14 @@ def execute(self, test: CompiledTestNode, manifest: Manifest): else: status = TestStatus.Pass - return TestResult( + return RunResult( node=test, status=status, timing=[], thread_id=thread_id, execution_time=0, message=message, - failures=result.failures, + failures=int(result.failures), adapter_response={}, )