Skip to content

Commit c2bc2f0

Browse files
authored
adding clean_up methods to basic and unique_id tests (#9195)
* init attempt of adding clean_up methods to basic and unique_id tests * swapping cleanup method drop of test_schema to unique_schema to test breakage on docs_generate test * moving the clean_up method down into class BaseDocsGenerate * remove drop relation for unique_schema * manually define alternate_schema for clean_up as not being seen as part of project_config * add changelog * remove unneeded changelog * uncomment line that generates new manifest and delete manifest our changes created * make sure the manifest test is deleted and readd older version of manifest.json to appease test * manually revert file to previous commit * Revert "manually revert file to previous commit" This reverts commit a755419.
1 parent 6e0a387 commit c2bc2f0

12 files changed

+113
-2
lines changed

tests/adapter/dbt/tests/adapter/basic/test_adapter_methods.py

+11
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ def project_config_update(self):
9090
"name": "adapter_methods",
9191
}
9292

93+
@pytest.fixture(autouse=True)
94+
def clean_up(self, project):
95+
yield
96+
with project.adapter.connection_named("__test"):
97+
relation = project.adapter.Relation.create(
98+
database=project.database, schema=project.test_schema
99+
)
100+
project.adapter.drop_schema(relation)
101+
102+
pass
103+
93104
# snowflake need all tables in CAP name
94105
@pytest.fixture(scope="class")
95106
def equal_tables(self):

tests/adapter/dbt/tests/adapter/basic/test_base.py

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ def project_config_update(self):
3737
"name": "base",
3838
}
3939

40+
@pytest.fixture(autouse=True)
41+
def clean_up(self, project):
42+
yield
43+
with project.adapter.connection_named("__test"):
44+
relation = project.adapter.Relation.create(
45+
database=project.database, schema=project.test_schema
46+
)
47+
project.adapter.drop_schema(relation)
48+
49+
pass
50+
4051
def test_base(self, project):
4152

4253
# seed command

tests/adapter/dbt/tests/adapter/basic/test_docs_generate.py

+12
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ def expected_catalog(self, project, profile_user):
428428
model_stats=no_stats(),
429429
)
430430

431+
@pytest.fixture(autouse=True)
432+
def clean_up(self, project):
433+
yield
434+
with project.adapter.connection_named("__test"):
435+
alternate_schema = f"{project.test_schema}_test"
436+
relation = project.adapter.Relation.create(
437+
database=project.database, schema=alternate_schema
438+
)
439+
project.adapter.drop_schema(relation)
440+
441+
pass
442+
431443
# Test "--no-compile" flag works and produces no manifest.json
432444
def test_run_and_generate_no_compile(self, project, expected_catalog):
433445
start_time = run_and_generate(project, ["--no-compile"])

tests/adapter/dbt/tests/adapter/basic/test_generic_tests.py

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def models(self):
3333
"schema_table.yml": generic_test_table_yml,
3434
}
3535

36+
@pytest.fixture(autouse=True)
37+
def clean_up(self, project):
38+
yield
39+
with project.adapter.connection_named("__test"):
40+
relation = project.adapter.Relation.create(
41+
database=project.database, schema=project.test_schema
42+
)
43+
project.adapter.drop_schema(relation)
44+
45+
pass
46+
3647
def test_generic_tests(self, project):
3748
# seed command
3849
results = run_dbt(["seed"])

tests/adapter/dbt/tests/adapter/basic/test_incremental.py

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ def models(self):
2323
def seeds(self):
2424
return {"base.csv": seeds_base_csv, "added.csv": seeds_added_csv}
2525

26+
@pytest.fixture(autouse=True)
27+
def clean_up(self, project):
28+
yield
29+
with project.adapter.connection_named("__test"):
30+
relation = project.adapter.Relation.create(
31+
database=project.database, schema=project.test_schema
32+
)
33+
project.adapter.drop_schema(relation)
34+
35+
pass
36+
2637
def test_incremental(self, project):
2738
# seed command
2839
results = run_dbt(["seed"])

tests/adapter/dbt/tests/adapter/basic/test_singular_tests.py

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ def tests(self):
1818
def project_config_update(self):
1919
return {"name": "singular_tests"}
2020

21+
@pytest.fixture(autouse=True)
22+
def clean_up(self, project):
23+
yield
24+
with project.adapter.connection_named("__test"):
25+
relation = project.adapter.Relation.create(
26+
database=project.database, schema=project.test_schema
27+
)
28+
project.adapter.drop_schema(relation)
29+
30+
pass
31+
2132
def test_singular_tests(self, project):
2233
# test command
2334
results = run_dbt(["test"], expect_pass=False)

tests/adapter/dbt/tests/adapter/basic/test_singular_tests_ephemeral.py

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def project_config_update(self):
3939
"name": "singular_tests_ephemeral",
4040
}
4141

42+
@pytest.fixture(autouse=True)
43+
def clean_up(self, project):
44+
yield
45+
with project.adapter.connection_named("__test"):
46+
relation = project.adapter.Relation.create(
47+
database=project.database, schema=project.test_schema
48+
)
49+
project.adapter.drop_schema(relation)
50+
51+
pass
52+
4253
def test_singular_tests_ephemeral(self, project):
4354
# check results from seed command
4455
results = run_dbt(["seed"])

tests/adapter/dbt/tests/adapter/basic/test_snapshot_check_cols.py

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ def snapshots(self):
3535
"cc_name_snapshot.sql": cc_name_snapshot_sql,
3636
}
3737

38+
@pytest.fixture(autouse=True)
39+
def clean_up(self, project):
40+
yield
41+
with project.adapter.connection_named("__test"):
42+
relation = project.adapter.Relation.create(
43+
database=project.database, schema=project.test_schema
44+
)
45+
project.adapter.drop_schema(relation)
46+
47+
pass
48+
3849
def test_snapshot_check_cols(self, project):
3950
# seed command
4051
results = run_dbt(["seed"])

tests/adapter/dbt/tests/adapter/basic/test_snapshot_timestamp.py

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def snapshots(self):
3333
def project_config_update(self):
3434
return {"name": "snapshot_strategy_timestamp"}
3535

36+
@pytest.fixture(autouse=True)
37+
def clean_up(self, project):
38+
yield
39+
with project.adapter.connection_named("__test"):
40+
relation = project.adapter.Relation.create(
41+
database=project.database, schema=project.test_schema
42+
)
43+
project.adapter.drop_schema(relation)
44+
45+
pass
46+
3647
def test_snapshot_timestamp(self, project):
3748
# seed command
3849
results = run_dbt(["seed"])

tests/adapter/dbt/tests/adapter/incremental/test_incremental_unique_id.py

+11
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ def seeds(self):
344344
"add_new_rows.sql": seeds__add_new_rows_sql,
345345
}
346346

347+
@pytest.fixture(autouse=True)
348+
def clean_up(self, project):
349+
yield
350+
with project.adapter.connection_named("__test"):
351+
relation = project.adapter.Relation.create(
352+
database=project.database, schema=project.test_schema
353+
)
354+
project.adapter.drop_schema(relation)
355+
356+
pass
357+
347358
def update_incremental_model(self, incremental_model):
348359
"""update incremental model after the seed table has been updated"""
349360
model_result_set = run_dbt(["run", "--select", incremental_model])

tests/functional/artifacts/data/state/v12/manifest.json

+1-1
Large diffs are not rendered by default.

tests/functional/artifacts/test_previous_version_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_compare_state_current(self, project):
412412
current_manifest_schema_version == self.CURRENT_EXPECTED_MANIFEST_VERSION
413413
), "Sounds like you've bumped the manifest version and need to update this test!"
414414
# If we need a newly generated manifest, uncomment the following line and commit the result
415-
self.generate_latest_manifest(project, current_manifest_schema_version)
415+
# self.generate_latest_manifest(project, current_manifest_schema_version)
416416
self.compare_previous_state(project, current_manifest_schema_version, True, 0)
417417

418418
def test_backwards_compatible_versions(self, project):

0 commit comments

Comments
 (0)