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

Fix configuration of turning test warnings into failures #9347

Merged
merged 5 commits into from
Apr 10, 2024
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240108-232035.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: fix configuration of turning test warnings into failures with WARN_ERROR_OPTIONS
time: 2024-01-08T23:20:35.339102+09:00
custom:
Author: jx2lee
Issue: "7761"
7 changes: 5 additions & 2 deletions core/dbt/task/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

class TestRunner(CompileRunner):
_ANSI_ESCAPE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
_LOG_TEST_RESULT_EVENTS = LogTestResult

def describe_node_name(self):
if self.node.resource_type == NodeType.Unit:
Expand All @@ -102,7 +103,7 @@
model = result.node

fire_event(
LogTestResult(
self._LOG_TEST_RESULT_EVENTS(
name=self.describe_node_name(),
MichelleArk marked this conversation as resolved.
Show resolved Hide resolved
status=str(result.status),
index=self.node_index,
Expand Down Expand Up @@ -280,7 +281,9 @@
message = f"Got {num_errors}, configured to fail if {test.config.error_if}"
failures = result.failures
elif result.should_warn:
if get_flags().WARN_ERROR:
if get_flags().WARN_ERROR or get_flags().WARN_ERROR_OPTIONS.includes(

Check warning on line 284 in core/dbt/task/test.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/test.py#L284

Added line #L284 was not covered by tests
self._LOG_TEST_RESULT_EVENTS.__name__
):
status = TestStatus.Fail
message = f"Got {num_errors}, configured to fail if {test.config.warn_if}"
else:
Expand Down
34 changes: 34 additions & 0 deletions tests/functional/test_singular_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from dbt.tests.util import run_dbt

single_test_sql = """
{{ config(warn_if = '>0', error_if ="> 10") }}

select 1 as issue
"""


class TestSingularTestWarnError:
@pytest.fixture(scope="class")
def tests(self):
return {"single_test.sql": single_test_sql}

def test_singular_test_warn_error(self, project):
results = run_dbt(["--warn-error", "test"], expect_pass=False)
assert results.results[0].status == "fail"

def test_singular_test_warn_error_options(self, project):
results = run_dbt(
["--warn-error-options", "{'include': 'all'}", "test"], expect_pass=False
)
assert results.results[0].status == "fail"

def test_singular_test_equals_warn_error(self, project):
results = run_dbt(["--warn-error", "test"], expect_pass=False)
warn_error_result = results.results[0].status

results = run_dbt(
["--warn-error-options", "{'include': 'all'}", "test"], expect_pass=False
)
assert warn_error_result == results.results[0].status