Skip to content

Commit

Permalink
add failures field
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley committed May 21, 2021
1 parent 618c6f8 commit 64b4d3f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
6 changes: 1 addition & 5 deletions core/dbt/contracts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions core/dbt/task/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dbt import utils

from dbt.contracts.results import (
FreshnessStatus, NodeResult, NodeStatus, TestStatus
FreshnessStatus, NodeStatus, TestStatus
)


Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions core/dbt/task/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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={},
)

Expand Down

0 comments on commit 64b4d3f

Please sign in to comment.