Skip to content

Commit

Permalink
Add test case for #10017
Browse files Browse the repository at this point in the history
  • Loading branch information
jtcohen6 committed May 2, 2024
1 parent 7854bfa commit 1377431
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/functional/unit_testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
22 changes: 22 additions & 0 deletions tests/functional/unit_testing/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -131,3 +134,22 @@ 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"]

0 comments on commit 1377431

Please sign in to comment.