From 1b1f3b298f39c78177d9c483a844febebad26508 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 12 Sep 2023 10:59:56 -0500 Subject: [PATCH] split up test class (#8610) (cherry picked from commit 5182e3c40c9aadcafdb77e7fdcd6091ae0277444) --- tests/functional/show/test_show.py | 61 +++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/tests/functional/show/test_show.py b/tests/functional/show/test_show.py index 35c0fcb40d4..42bddb2ddee 100644 --- a/tests/functional/show/test_show.py +++ b/tests/functional/show/test_show.py @@ -16,7 +16,7 @@ ) -class TestShow: +class ShowBase: @pytest.fixture(scope="class") def models(self): return { @@ -32,43 +32,54 @@ def models(self): def seeds(self): return {"sample_seed.csv": seeds__sample_seed} + @pytest.fixture(scope="class", autouse=True) + def setup(self, project): + run_dbt(["seed"]) + + +class TestShowNone(ShowBase): def test_none(self, project): with pytest.raises( DbtRuntimeError, match="Either --select or --inline must be passed to show" ): - run_dbt(["seed"]) run_dbt(["show"]) + +class TestShowSelectText(ShowBase): def test_select_model_text(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture(["show", "--select", "second_model"]) + (_, log_output) = run_dbt_and_capture(["show", "--select", "second_model"]) assert "Previewing node 'sample_model'" not in log_output assert "Previewing node 'second_model'" in log_output assert "col_one" in log_output assert "col_two" in log_output assert "answer" in log_output + +class TestShowMultiple(ShowBase): def test_select_multiple_model_text(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( - ["show", "--select", "sample_model second_model"] - ) + (_, log_output) = run_dbt_and_capture(["show", "--select", "sample_model second_model"]) assert "Previewing node 'sample_model'" in log_output assert "sample_num" in log_output assert "sample_bool" in log_output + +class TestShowSingle(ShowBase): def test_select_single_model_json(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( + (_, log_output) = run_dbt_and_capture( ["show", "--select", "sample_model", "--output", "json"] ) assert "Previewing node 'sample_model'" not in log_output assert "sample_num" in log_output assert "sample_bool" in log_output + +class TestShowNumeric(ShowBase): def test_numeric_values(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( + (_, log_output) = run_dbt_and_capture( ["show", "--select", "sample_number_model", "--output", "json"] ) assert "Previewing node 'sample_number_model'" not in log_output @@ -79,9 +90,11 @@ def test_numeric_values(self, project): assert "5" in log_output assert "5.0" not in log_output + +class TestShowNumericNulls(ShowBase): def test_numeric_values_with_nulls(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( + (_, log_output) = run_dbt_and_capture( ["show", "--select", "sample_number_model_with_nulls", "--output", "json"] ) assert "Previewing node 'sample_number_model_with_nulls'" not in log_output @@ -92,35 +105,45 @@ def test_numeric_values_with_nulls(self, project): assert "5" in log_output assert "5.0" not in log_output + +class TestShowInline(ShowBase): def test_inline_pass(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( + (_, log_output) = run_dbt_and_capture( ["show", "--inline", "select * from {{ ref('sample_model') }}"] ) assert "Previewing inline node" in log_output assert "sample_num" in log_output assert "sample_bool" in log_output + +class TestShowInlineFail(ShowBase): def test_inline_fail(self, project): with pytest.raises(DbtException, match="Error parsing inline query"): run_dbt(["show", "--inline", "select * from {{ ref('third_model') }}"]) + +class TestShowInlineFailDB(ShowBase): def test_inline_fail_database_error(self, project): with pytest.raises(DbtRuntimeError, match="Database Error"): run_dbt(["show", "--inline", "slect asdlkjfsld;j"]) + +class TestShowEphemeral(ShowBase): def test_ephemeral_model(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture(["show", "--select", "ephemeral_model"]) + (_, log_output) = run_dbt_and_capture(["show", "--select", "ephemeral_model"]) assert "col_deci" in log_output + +class TestShowSecondEphemeral(ShowBase): def test_second_ephemeral_model(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture( - ["show", "--inline", models__second_ephemeral_model] - ) + (_, log_output) = run_dbt_and_capture(["show", "--inline", models__second_ephemeral_model]) assert "col_hundo" in log_output + +class TestShowLimit(ShowBase): @pytest.mark.parametrize( "args,expected", [ @@ -132,16 +155,20 @@ def test_second_ephemeral_model(self, project): def test_limit(self, project, args, expected): run_dbt(["build"]) dbt_args = ["show", "--inline", models__second_ephemeral_model, *args] - results, log_output = run_dbt_and_capture(dbt_args) + results = run_dbt(dbt_args) assert len(results.results[0].agate_table) == expected + +class TestShowSeed(ShowBase): def test_seed(self, project): - (results, log_output) = run_dbt_and_capture(["show", "--select", "sample_seed"]) + (_, log_output) = run_dbt_and_capture(["show", "--select", "sample_seed"]) assert "Previewing node 'sample_seed'" in log_output + +class TestShowSqlHeader(ShowBase): def test_sql_header(self, project): run_dbt(["build"]) - (results, log_output) = run_dbt_and_capture(["show", "--select", "sql_header"]) + (_, log_output) = run_dbt_and_capture(["show", "--select", "sql_header"]) assert "Asia/Kolkata" in log_output