Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding clean_up methods to basic and unique_id tests #9195

Merged
merged 13 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231211-112858.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to just tests should not have a changelog.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add clean_up methods to various core defined tests
time: 2023-12-11T11:28:58.507371-06:00
custom:
Author: McKnight-42
Issue: "9219"
11 changes: 11 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_adapter_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def project_config_update(self):
"name": "adapter_methods",
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

# snowflake need all tables in CAP name
@pytest.fixture(scope="class")
def equal_tables(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def project_config_update(self):
"name": "base",
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_base(self, project):

# seed command
Expand Down
12 changes: 12 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_docs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,18 @@ def expected_catalog(self, project, profile_user):
model_stats=no_stats(),
)

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
alternate_schema = f"{project.test_schema}_test"
relation = project.adapter.Relation.create(
database=project.database, schema=alternate_schema
)
project.adapter.drop_schema(relation)

pass

# Test "--no-compile" flag works and produces no manifest.json
def test_run_and_generate_no_compile(self, project, expected_catalog):
start_time = run_and_generate(project, ["--no-compile"])
Expand Down
11 changes: 11 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_generic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def models(self):
"schema_table.yml": generic_test_table_yml,
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_generic_tests(self, project):
# seed command
results = run_dbt(["seed"])
Expand Down
11 changes: 11 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ def models(self):
def seeds(self):
return {"base.csv": seeds_base_csv, "added.csv": seeds_added_csv}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_incremental(self, project):
# seed command
results = run_dbt(["seed"])
Expand Down
11 changes: 11 additions & 0 deletions tests/adapter/dbt/tests/adapter/basic/test_singular_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def tests(self):
def project_config_update(self):
return {"name": "singular_tests"}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_singular_tests(self, project):
# test command
results = run_dbt(["test"], expect_pass=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def project_config_update(self):
"name": "singular_tests_ephemeral",
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_singular_tests_ephemeral(self, project):
# check results from seed command
results = run_dbt(["seed"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def snapshots(self):
"cc_name_snapshot.sql": cc_name_snapshot_sql,
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_snapshot_check_cols(self, project):
# seed command
results = run_dbt(["seed"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def snapshots(self):
def project_config_update(self):
return {"name": "snapshot_strategy_timestamp"}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_snapshot_timestamp(self, project):
# seed command
results = run_dbt(["seed"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ def seeds(self):
"add_new_rows.sql": seeds__add_new_rows_sql,
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def update_incremental_model(self, incremental_model):
"""update incremental model after the seed table has been updated"""
model_result_set = run_dbt(["run", "--select", incremental_model])
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/artifacts/data/state/v12/manifest.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these changes require manifest changes?

Copy link
Contributor Author

@McKnight-42 McKnight-42 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly, this seemed to change every time I did a git add . i didn't manually change anything in it. @emmyoop any ideas as to why it would of updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! That's because this line is uncommented! It should be commented out. Looks like it got accidentally merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment it out and delete your manifest generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay after deleting the line, and the manifest we would have some failures in the test for not having a manifest to compare to so I grabbed the one generated from the above pr.

Copy link
Member

@emmyoop emmyoop Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, by "delete your generated manifest" I meant to revert the changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert the file instead of generating a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try i just copy/pasted it from Quigley's pr

Large diffs are not rendered by default.