From b1b4b5f9f8dac0e98e32a523e001de85835c2a08 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Thu, 2 May 2024 02:33:50 +0200 Subject: [PATCH] Add test case for #10017 --- tests/functional/unit_testing/fixtures.py | 19 +++++++++++++++++ tests/functional/unit_testing/test_state.py | 23 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/functional/unit_testing/fixtures.py b/tests/functional/unit_testing/fixtures.py index 54f0497250a..56f4e22210b 100644 --- a/tests/functional/unit_testing/fixtures.py +++ b/tests/functional/unit_testing/fixtures.py @@ -1041,3 +1041,22 @@ def external_package(): "external_model.sql": external_package__external_model_sql, }, } + + +model_select_1_sql = """ +select 1 as id +""" + +model_select_2_sql = """ +select 2 as id +""" + +test_expect_2_yml = """ +unit_tests: + - name: test_my_model + model: my_model + given: [] + expect: + rows: + - {id: 2} +""" diff --git a/tests/functional/unit_testing/test_state.py b/tests/functional/unit_testing/test_state.py index 1d56fa8c221..4df874726d0 100644 --- a/tests/functional/unit_testing/test_state.py +++ b/tests/functional/unit_testing/test_state.py @@ -15,6 +15,9 @@ test_my_model_simple_fixture_yml, test_my_model_fixture_csv, test_my_model_b_fixture_csv as test_my_model_fixture_csv_modified, + model_select_1_sql, + model_select_2_sql, + test_expect_2_yml, ) @@ -131,3 +134,23 @@ def test_unit_test_defer_state(self, project): results = run_dbt(["test", "--defer", "--state", "state"], expect_pass=False) assert len(results) == 4 assert sorted([r.status for r in results]) == ["fail", "pass", "pass", "pass"] + + + +class TestUnitTestDeferDoesntOverwrite(UnitTestState): + @pytest.fixture(scope="class") + def models(self): + return {"my_model.sql": model_select_1_sql, "test_my_model.yml": test_expect_2_yml} + + def test_unit_test_defer_state(self, project): + run_dbt(["test"], expect_pass=False) + self.copy_state(project.project_root) + write_file( + model_select_2_sql, + project.project_root, + "models", + "my_model.sql", + ) + results = run_dbt(["test", "--defer", "--state", "state"]) + assert len(results) == 1 + assert sorted([r.status for r in results]) == ["pass"]