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

Convert color tests to pytest #6230

Merged
merged 3 commits into from
Nov 8, 2022
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
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20221108-133104.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Convert use color tests to pytest
time: 2022-11-08T13:31:04.788547-06:00
custom:
Author: stu-k
Issue: "5771"
PR: "6230"

This file was deleted.

29 changes: 0 additions & 29 deletions test/integration/061_use_colors_tests/test_no_use_colors.py

This file was deleted.

29 changes: 0 additions & 29 deletions test/integration/061_use_colors_tests/test_use_colors.py

This file was deleted.

43 changes: 43 additions & 0 deletions tests/functional/colors/test_colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
import re
from dbt.tests.util import run_dbt_and_capture


models__do_nothing_then_fail_sql = """
select 1,

"""


@pytest.fixture(scope="class")
def models():
return {"do_nothing_then_fail.sql": models__do_nothing_then_fail_sql}


@pytest.fixture(scope="class")
def project_config_update():
return {'config-version': 2}


class TestColors:
def test_use_colors(self, project):
self.assert_colors_used(
"--use-colors",
expect_colors=True,
)

def test_no_use_colors(self, project):
self.assert_colors_used(
"--no-use-colors",
expect_colors=False,
)

def assert_colors_used(self, flag, expect_colors):
_, stdout = run_dbt_and_capture(args=[flag, "run"], expect_pass=False)
# pattern to match formatted log output
pattern = re.compile(r"\[31m.*|\[33m.*")
stdout_contains_formatting_characters = bool(pattern.search(stdout))
if expect_colors:
assert stdout_contains_formatting_characters
else:
assert not stdout_contains_formatting_characters