diff --git a/.changes/unreleased/Under the Hood-20221108-133104.yaml b/.changes/unreleased/Under the Hood-20221108-133104.yaml new file mode 100644 index 00000000000..4aea5ee8cd9 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20221108-133104.yaml @@ -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" diff --git a/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql b/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql deleted file mode 100644 index 30f1a53ec18..00000000000 --- a/test/integration/061_use_colors_tests/models/do_nothing_then_fail.sql +++ /dev/null @@ -1 +0,0 @@ -select 1, diff --git a/test/integration/061_use_colors_tests/test_no_use_colors.py b/test/integration/061_use_colors_tests/test_no_use_colors.py deleted file mode 100644 index a923c8d855e..00000000000 --- a/test/integration/061_use_colors_tests/test_no_use_colors.py +++ /dev/null @@ -1,29 +0,0 @@ - -from test.integration.base import DBTIntegrationTest, use_profile -import logging -import re -import sys - -class TestNoUseColors(DBTIntegrationTest): - - @property - def project_config(self): - return {'config-version': 2} - - @property - def schema(self): - return "use_colors_tests_061" - - @property - def models(self): - return "models" - - @use_profile('postgres') - def test_postgres_no_use_colors(self): - # pattern to match formatted log output - pattern = re.compile(r'\[31m.*|\[33m.*') - - results, stdout = self.run_dbt_and_capture(args=['--no-use-colors', 'run'], expect_pass=False) - - stdout_contains_formatting_characters = bool(pattern.search(stdout)) - self.assertFalse(stdout_contains_formatting_characters) diff --git a/test/integration/061_use_colors_tests/test_use_colors.py b/test/integration/061_use_colors_tests/test_use_colors.py deleted file mode 100644 index 6b3dac6a1f1..00000000000 --- a/test/integration/061_use_colors_tests/test_use_colors.py +++ /dev/null @@ -1,29 +0,0 @@ - -from test.integration.base import DBTIntegrationTest, use_profile -import logging -import re -import sys - -class TestUseColors(DBTIntegrationTest): - - @property - def project_config(self): - return {'config-version': 2} - - @property - def schema(self): - return "use_colors_tests_061" - - @property - def models(self): - return "models" - - @use_profile('postgres') - def test_postgres_use_colors(self): - # pattern to match formatted log output - pattern = re.compile(r'\[31m.*|\[33m.*') - - results, stdout = self.run_dbt_and_capture(args=['--use-colors', 'run'], expect_pass=False) - - stdout_contains_formatting_characters = bool(pattern.search(stdout)) - self.assertTrue(stdout_contains_formatting_characters) diff --git a/tests/functional/colors/test_colors.py b/tests/functional/colors/test_colors.py new file mode 100644 index 00000000000..7e92e039506 --- /dev/null +++ b/tests/functional/colors/test_colors.py @@ -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