From ccf5b12873bcb5031fc2d5acb646b482315bc1a8 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Fri, 16 Feb 2024 13:23:16 -0500 Subject: [PATCH 1/3] create separate base class for test body so that they can be imported into adapter implementations without running automatically --- dbt/tests/adapter/caching/test_caching.py | 6 +- .../adapter/column_types/test_column_types.py | 6 +- .../adapter/concurrency/test_concurrency.py | 6 +- .../adapter/constraints/test_constraints.py | 6 +- dbt/tests/adapter/dbt_clone/test_dbt_clone.py | 6 +- dbt/tests/adapter/dbt_debug/test_dbt_debug.py | 10 ++- dbt/tests/adapter/ephemeral/test_ephemeral.py | 18 ++++- dbt/tests/adapter/hooks/test_model_hooks.py | 76 +++++++++++++++---- dbt/tests/adapter/hooks/test_run_hooks.py | 12 ++- .../simple_copy/test_copy_uppercase.py | 6 +- dbt/tests/adapter/simple_seed/test_seed.py | 66 +++++++++++++--- .../test_store_test_failures.py | 6 +- 12 files changed, 182 insertions(+), 42 deletions(-) diff --git a/dbt/tests/adapter/caching/test_caching.py b/dbt/tests/adapter/caching/test_caching.py index 077849f7..60844513 100644 --- a/dbt/tests/adapter/caching/test_caching.py +++ b/dbt/tests/adapter/caching/test_caching.py @@ -92,7 +92,7 @@ def test_cache(self, project): self.run_and_inspect_cache(project, run_args) -class TestNoPopulateCache(BaseCachingTest): +class BaseNoPopulateCache(BaseCachingTest): @pytest.fixture(scope="class") def models(self): return { @@ -116,3 +116,7 @@ class TestCachingUppercaseModel(BaseCachingUppercaseModel): class TestCachingSelectedSchemaOnly(BaseCachingSelectedSchemaOnly): pass + + +class TestNoPopulateCache(BaseNoPopulateCache): + pass diff --git a/dbt/tests/adapter/column_types/test_column_types.py b/dbt/tests/adapter/column_types/test_column_types.py index 20e97660..1f99d610 100644 --- a/dbt/tests/adapter/column_types/test_column_types.py +++ b/dbt/tests/adapter/column_types/test_column_types.py @@ -15,11 +15,13 @@ def run_and_test(self): results = run_dbt(["test"]) assert len(results) == 1 - -class TestPostgresColumnTypes(BaseColumnTypes): @pytest.fixture(scope="class") def models(self): return {"model.sql": fixtures.model_sql, "schema.yml": fixtures.schema_yml} def test_run_and_test(self, project): self.run_and_test() + + +class TestPostgresColumnTypes(BaseColumnTypes): + pass diff --git a/dbt/tests/adapter/concurrency/test_concurrency.py b/dbt/tests/adapter/concurrency/test_concurrency.py index d6bf1449..b4eec93e 100644 --- a/dbt/tests/adapter/concurrency/test_concurrency.py +++ b/dbt/tests/adapter/concurrency/test_concurrency.py @@ -303,8 +303,6 @@ def models(self): "skip.sql": models__skip_sql, } - -class TestConcurenncy(BaseConcurrency): def test_concurrency(self, project): run_dbt(["seed", "--select", "seed"]) results = run_dbt(["run"], expect_pass=False) @@ -329,3 +327,7 @@ def test_concurrency(self, project): check_table_does_not_exist(project.adapter, "skip") assert "PASS=5 WARN=0 ERROR=1 SKIP=1 TOTAL=7" in output + + +class TestConcurenncy(BaseConcurrency): + pass diff --git a/dbt/tests/adapter/constraints/test_constraints.py b/dbt/tests/adapter/constraints/test_constraints.py index 27f3dbf3..85c9ae55 100644 --- a/dbt/tests/adapter/constraints/test_constraints.py +++ b/dbt/tests/adapter/constraints/test_constraints.py @@ -508,7 +508,7 @@ class TestConstraintQuotedColumn(BaseConstraintQuotedColumn): pass -class TestIncrementalForeignKeyConstraint: +class BaseIncrementalForeignKeyConstraint: @pytest.fixture(scope="class") def macros(self): return { @@ -534,3 +534,7 @@ def test_incremental_foreign_key_constraint(self, project): run_dbt(["run", "--select", "raw_numbers"]) run_dbt(["run", "--select", "stg_numbers"]) run_dbt(["run", "--select", "stg_numbers"]) + + +class TestIncrementalForeignKeyConstraint(BaseIncrementalForeignKeyConstraint): + pass diff --git a/dbt/tests/adapter/dbt_clone/test_dbt_clone.py b/dbt/tests/adapter/dbt_clone/test_dbt_clone.py index a45dee16..61472d1a 100644 --- a/dbt/tests/adapter/dbt_clone/test_dbt_clone.py +++ b/dbt/tests/adapter/dbt_clone/test_dbt_clone.py @@ -207,7 +207,7 @@ def clean_up(self, project): pass -class TestCloneSameTargetAndState(BaseClone): +class BaseCloneSameTargetAndState(BaseClone): def test_clone_same_target_and_state(self, project, unique_schema, other_schema): project.create_test_schema(other_schema) self.run_and_save_state(project.project_root) @@ -220,3 +220,7 @@ def test_clone_same_target_and_state(self, project, unique_schema, other_schema) results, output = run_dbt_and_capture(clone_args, expect_pass=False) assert "Warning: The state and target directories are the same: 'target'" in output + + +class TestCloneSameTargetAndState(BaseCloneSameTargetAndState): + pass diff --git a/dbt/tests/adapter/dbt_debug/test_dbt_debug.py b/dbt/tests/adapter/dbt_debug/test_dbt_debug.py index 7ce73304..a015b539 100644 --- a/dbt/tests/adapter/dbt_debug/test_dbt_debug.py +++ b/dbt/tests/adapter/dbt_debug/test_dbt_debug.py @@ -49,7 +49,7 @@ def project_config_update(self): return {"config-version": 2, "profile": '{{ "te" ~ "st" }}'} -class TestDebugPostgres(BaseDebug): +class BaseDebugPostgres(BaseDebug): def test_ok(self, project): run_dbt(["debug"]) assert "ERROR" not in self.capsys.readouterr().out @@ -85,11 +85,11 @@ def test_empty_target(self, project): self.assertGotValue(re.compile(r"\s+output 'none_target'"), "misconfigured") -class TestDebugProfileVariablePostgres(BaseDebugProfileVariable): +class TestDebugPostgres(BaseDebugPostgres): pass -class TestDebugInvalidProjectPostgres(BaseDebug): +class BaseDebugInvalidProjectPostgres(BaseDebug): def test_empty_project(self, project): with open("dbt_project.yml", "w") as f: # noqa: F841 pass @@ -128,3 +128,7 @@ def test_profile_not_found(self, project): ) assert "Profile loading failed for the following reason" in out assert "Could not find profile named 'NONE'" in out + + +class TestDebugInvalidProjectPostgres(BaseDebugInvalidProjectPostgres): + pass diff --git a/dbt/tests/adapter/ephemeral/test_ephemeral.py b/dbt/tests/adapter/ephemeral/test_ephemeral.py index efbfa77e..3021e284 100644 --- a/dbt/tests/adapter/ephemeral/test_ephemeral.py +++ b/dbt/tests/adapter/ephemeral/test_ephemeral.py @@ -248,8 +248,6 @@ def models(self): }, } - -class TestEphemeralMulti(BaseEphemeralMulti): def test_ephemeral_multi(self, project): run_dbt(["seed"]) results = run_dbt(["run"]) @@ -281,7 +279,11 @@ def test_ephemeral_multi(self, project): assert sql_file == expected_sql -class TestEphemeralNested(BaseEphemeral): +class TestEphemeralMulti(BaseEphemeralMulti): + pass + + +class BaseEphemeralNested(BaseEphemeral): @pytest.fixture(scope="class") def models(self): return { @@ -314,7 +316,11 @@ def test_ephemeral_nested(self, project): assert sql_file == expected_sql -class TestEphemeralErrorHandling(BaseEphemeral): +class TestEphemeralNested(BaseEphemeralNested): + pass + + +class BaseEphemeralErrorHandling(BaseEphemeral): @pytest.fixture(scope="class") def models(self): return { @@ -330,3 +336,7 @@ def test_ephemeral_error_handling(self, project): assert len(results) == 1 assert results[0].status == "skipped" assert "Compilation Error" in results[0].message + + +class TestEphemeralErrorHandling(BaseEphemeralErrorHandling): + pass diff --git a/dbt/tests/adapter/hooks/test_model_hooks.py b/dbt/tests/adapter/hooks/test_model_hooks.py index 333d975d..5f603d7c 100644 --- a/dbt/tests/adapter/hooks/test_model_hooks.py +++ b/dbt/tests/adapter/hooks/test_model_hooks.py @@ -121,7 +121,7 @@ def check_hooks(self, state, project, host, count=1): assert ctx["thread_id"].startswith("Thread-") -class TestPrePostModelHooks(BaseTestPrePost): +class BasePrePostModelHooks(BaseTestPrePost): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -153,7 +153,11 @@ def test_pre_and_post_run_hooks(self, project, dbt_profile_target): self.check_hooks("end", project, dbt_profile_target.get("host", None)) -class TestPrePostModelHooksUnderscores(TestPrePostModelHooks): +class TestPrePostModelHooks(BasePrePostModelHooks): + pass + + +class TestPrePostModelHooksUnderscores(BasePrePostModelHooks): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -176,7 +180,7 @@ def project_config_update(self): } -class TestHookRefs(BaseTestPrePost): +class BaseHookRefs(BaseTestPrePost): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -219,7 +223,11 @@ def test_pre_post_model_hooks_refed(self, project, dbt_profile_target): self.check_hooks("end", project, dbt_profile_target.get("host", None)) -class TestPrePostModelHooksOnSeeds(object): +class TestHookRefs(BaseHookRefs): + pass + + +class BasePrePostModelHooksOnSeeds: @pytest.fixture(scope="class") def seeds(self): return {"example_seed.csv": fixtures.seeds__example_seed_csv} @@ -251,7 +259,11 @@ def test_hooks_on_seeds(self, project): assert len(res) == 1, "Expected exactly one item" -class TestHooksRefsOnSeeds: +class TestPrePostModelHooksOnSeeds(BasePrePostModelHooksOnSeeds): + pass + + +class BaseHooksRefsOnSeeds: """ This should not succeed, and raise an explicit error https://github.com/dbt-labs/dbt-core/issues/6806 @@ -281,7 +293,11 @@ def test_hook_with_ref_on_seeds(self, project): assert "Seeds cannot depend on other nodes" in str(excinfo.value) -class TestPrePostModelHooksOnSeedsPlusPrefixed(TestPrePostModelHooksOnSeeds): +class TestHooksRefsOnSeeds(BaseHooksRefsOnSeeds): + pass + + +class BasePrePostModelHooksOnSeedsPlusPrefixed(BasePrePostModelHooksOnSeeds): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -297,7 +313,11 @@ def project_config_update(self): } -class TestPrePostModelHooksOnSeedsPlusPrefixedWhitespace(TestPrePostModelHooksOnSeeds): +class TestPrePostModelHooksOnSeedsPlusPrefixed(BasePrePostModelHooksOnSeedsPlusPrefixed): + pass + + +class BasePrePostModelHooksOnSeedsPlusPrefixedWhitespace(BasePrePostModelHooksOnSeeds): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -313,7 +333,13 @@ def project_config_update(self): } -class TestPrePostModelHooksOnSnapshots(object): +class TestPrePostModelHooksOnSeedsPlusPrefixedWhitespace( + BasePrePostModelHooksOnSeedsPlusPrefixedWhitespace +): + pass + + +class BasePrePostModelHooksOnSnapshots: @pytest.fixture(scope="class", autouse=True) def setUp(self, project): path = Path(project.project_root) / "test-snapshots" @@ -354,6 +380,10 @@ def test_hooks_on_snapshots(self, project): assert len(res) == 1, "Expected exactly one item" +class TestPrePostModelHooksOnSnapshots(BasePrePostModelHooksOnSnapshots): + pass + + class PrePostModelHooksInConfigSetup(BaseTestPrePost): @pytest.fixture(scope="class") def project_config_update(self): @@ -366,7 +396,7 @@ def models(self): return {"hooks.sql": fixtures.models__hooks_configured} -class TestPrePostModelHooksInConfig(PrePostModelHooksInConfigSetup): +class BasePrePostModelHooksInConfig(PrePostModelHooksInConfigSetup): def test_pre_and_post_model_hooks_model(self, project, dbt_profile_target): run_dbt() @@ -374,7 +404,11 @@ def test_pre_and_post_model_hooks_model(self, project, dbt_profile_target): self.check_hooks("end", project, dbt_profile_target.get("host", None)) -class TestPrePostModelHooksInConfigWithCount(PrePostModelHooksInConfigSetup): +class TestPrePostModelHooksInConfig(BasePrePostModelHooksInConfig): + pass + + +class BasePrePostModelHooksInConfigWithCount(PrePostModelHooksInConfigSetup): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -403,13 +437,21 @@ def test_pre_and_post_model_hooks_model_and_project(self, project, dbt_profile_t self.check_hooks("end", project, dbt_profile_target.get("host", None), count=2) -class TestPrePostModelHooksInConfigKwargs(TestPrePostModelHooksInConfig): +class TestPrePostModelHooksInConfigWithCount(BasePrePostModelHooksInConfigWithCount): + pass + + +class BasePrePostModelHooksInConfigKwargs(BasePrePostModelHooksInConfig): @pytest.fixture(scope="class") def models(self): return {"hooks.sql": fixtures.models__hooks_kwargs} -class TestPrePostSnapshotHooksInConfigKwargs(TestPrePostModelHooksOnSnapshots): +class TestPrePostModelHooksInConfigKwargs(BasePrePostModelHooksInConfigKwargs): + pass + + +class BasePrePostSnapshotHooksInConfigKwargs(BasePrePostModelHooksOnSnapshots): @pytest.fixture(scope="class", autouse=True) def setUp(self, project): path = Path(project.project_root) / "test-kwargs-snapshots" @@ -434,7 +476,11 @@ def project_config_update(self): } -class TestDuplicateHooksInConfigs(object): +class TestPrePostSnapshotHooksInConfigKwargs(BasePrePostSnapshotHooksInConfigKwargs): + pass + + +class BaseDuplicateHooksInConfigs: @pytest.fixture(scope="class") def models(self): return {"hooks.sql": fixtures.models__hooks_error} @@ -444,3 +490,7 @@ def test_run_duplicate_hook_defs(self, project): run_dbt() assert "pre_hook" in str(exc.value) assert "pre-hook" in str(exc.value) + + +class TestDuplicateHooksInConfigs(BaseDuplicateHooksInConfigs): + pass diff --git a/dbt/tests/adapter/hooks/test_run_hooks.py b/dbt/tests/adapter/hooks/test_run_hooks.py index cb265928..89565c70 100644 --- a/dbt/tests/adapter/hooks/test_run_hooks.py +++ b/dbt/tests/adapter/hooks/test_run_hooks.py @@ -7,7 +7,7 @@ from dbt.tests.util import check_table_does_not_exist, run_dbt -class TestPrePostRunHooks(object): +class BasePrePostRunHooks: @pytest.fixture(scope="function") def setUp(self, project): project.run_sql_file(project.test_data_dir / Path("seed_run.sql")) @@ -135,7 +135,11 @@ def test_pre_and_post_seed_hooks(self, setUp, project, dbt_profile_target): self.assert_used_schemas(project) -class TestAfterRunHooks(object): +class TestPrePostRunHooks(BasePrePostRunHooks): + pass + + +class BaseAfterRunHooks: @pytest.fixture(scope="class") def macros(self): return {"temp_macro.sql": fixtures.macros_missing_column} @@ -155,3 +159,7 @@ def project_config_update(self): def test_missing_column_pre_hook(self, project): run_dbt(["run"], expect_pass=False) + + +class TestAfterRunHooks(BaseAfterRunHooks): + pass diff --git a/dbt/tests/adapter/simple_copy/test_copy_uppercase.py b/dbt/tests/adapter/simple_copy/test_copy_uppercase.py index 510e4f19..85a90206 100644 --- a/dbt/tests/adapter/simple_copy/test_copy_uppercase.py +++ b/dbt/tests/adapter/simple_copy/test_copy_uppercase.py @@ -4,7 +4,7 @@ from dbt.tests.util import run_dbt, check_relations_equal -class TestSimpleCopyUppercase: +class BaseSimpleCopyUppercase: @pytest.fixture(scope="class") def dbt_profile_target(self): return { @@ -53,3 +53,7 @@ def test_simple_copy_uppercase(self, project): check_relations_equal( project.adapter, ["seed", "VIEW_MODEL", "INCREMENTAL", "MATERIALIZED", "GET_AND_REF"] ) + + +class TestSimpleCopyUppercase(BaseSimpleCopyUppercase): + pass diff --git a/dbt/tests/adapter/simple_seed/test_seed.py b/dbt/tests/adapter/simple_seed/test_seed.py index 5617d282..08b8d8f3 100644 --- a/dbt/tests/adapter/simple_seed/test_seed.py +++ b/dbt/tests/adapter/simple_seed/test_seed.py @@ -64,7 +64,7 @@ def _check_relation_end_state(self, run_result, project, exists: bool): check_table_does_not_exist(project.adapter, "models__downstream_from_seed_actual") -class TestBasicSeedTests(SeedTestBase): +class BaseBasicSeedTests(SeedTestBase): def test_simple_seed(self, project): """Build models and observe that run truncates a seed and re-inserts rows""" self._build_relations_for_test(project) @@ -79,7 +79,11 @@ def test_simple_seed_full_refresh_flag(self, project): ) -class TestSeedConfigFullRefreshOn(SeedTestBase): +class TestBasicSeedTests(BaseBasicSeedTests): + pass + + +class BaseSeedConfigFullRefreshOn(SeedTestBase): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -92,7 +96,11 @@ def test_simple_seed_full_refresh_config(self, project): self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=False) -class TestSeedConfigFullRefreshOff(SeedTestBase): +class TestSeedConfigFullRefreshOn(BaseSeedConfigFullRefreshOn): + pass + + +class BaseSeedConfigFullRefreshOff(SeedTestBase): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -108,7 +116,11 @@ def test_simple_seed_full_refresh_config(self, project): ) -class TestSeedCustomSchema(SeedTestBase): +class TestSeedConfigFullRefreshOff(BaseSeedConfigFullRefreshOff): + pass + + +class BaseSeedCustomSchema(SeedTestBase): @pytest.fixture(scope="class", autouse=True) def setUp(self, project): """Create table for ensuring seeds and models used in tests build correctly""" @@ -148,6 +160,10 @@ def test_simple_seed_with_drop_and_schema(self, project): check_relations_equal(project.adapter, [f"{custom_schema}.seed_actual", "seed_expected"]) +class TestSeedCustomSchema(BaseSeedCustomSchema): + pass + + class SeedUniqueDelimiterTestBase(SeedConfigBase): @pytest.fixture(scope="class") def project_config_update(self): @@ -193,14 +209,18 @@ def _check_relation_end_state(self, run_result, project, exists: bool): ) -class TestSeedWithUniqueDelimiter(SeedUniqueDelimiterTestBase): +class BaseSeedWithUniqueDelimiter(SeedUniqueDelimiterTestBase): def test_seed_with_unique_delimiter(self, project): """Testing correct run of seeds with a unique delimiter (pipe in this case)""" self._build_relations_for_test(project) self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True) -class TestSeedWithWrongDelimiter(SeedUniqueDelimiterTestBase): +class TestSeedWithUniqueDelimiter(BaseSeedWithUniqueDelimiter): + pass + + +class BaseSeedWithWrongDelimiter(SeedUniqueDelimiterTestBase): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -213,7 +233,11 @@ def test_seed_with_wrong_delimiter(self, project): assert "syntax error" in seed_result.results[0].message.lower() -class TestSeedWithEmptyDelimiter(SeedUniqueDelimiterTestBase): +class TestSeedWithWrongDelimiter(BaseSeedWithWrongDelimiter): + pass + + +class BaseSeedWithEmptyDelimiter(SeedUniqueDelimiterTestBase): @pytest.fixture(scope="class") def project_config_update(self): return { @@ -226,7 +250,11 @@ def test_seed_with_empty_delimiter(self, project): assert "compilation error" in seed_result.results[0].message.lower() -class TestSimpleSeedEnabledViaConfig(object): +class TestSeedWithEmptyDelimiter(BaseSeedWithEmptyDelimiter): + pass + + +class BaseSimpleSeedEnabledViaConfig: @pytest.fixture(scope="session") def seeds(self): return { @@ -271,7 +299,11 @@ def test_simple_seed_exclude(self, clear_test_schema, project): check_table_does_exist(project.adapter, "seed_tricky") -class TestSeedParsing(SeedConfigBase): +class TestSimpleSeedEnabledViaConfig(BaseSimpleSeedEnabledViaConfig): + pass + + +class BaseSeedParsing(SeedConfigBase): @pytest.fixture(scope="class", autouse=True) def setUp(self, project): """Create table for ensuring seeds and models used in tests build correctly""" @@ -293,7 +325,11 @@ def test_dbt_run_skips_seeds(self, project): run_dbt(["seed"], expect_pass=False) -class TestSimpleSeedWithBOM(SeedConfigBase): +class TestSeedParsing(BaseSeedParsing): + pass + + +class BaseSimpleSeedWithBOM(SeedConfigBase): # Reference: BOM = byte order mark; see https://www.ibm.com/docs/en/netezza?topic=formats-byte-order-mark # Tests for hidden unicode character in csv @pytest.fixture(scope="class", autouse=True) @@ -319,7 +355,11 @@ def test_simple_seed(self, project): check_relations_equal(project.adapter, ["seed_expected", "seed_bom"]) -class TestSeedSpecificFormats(SeedConfigBase): +class TestSimpleSeedWithBOM(BaseSimpleSeedWithBOM): + pass + + +class BaseSeedSpecificFormats(SeedConfigBase): """Expect all edge cases to build""" @staticmethod @@ -350,6 +390,10 @@ def test_simple_seed(self, project): assert len(results) == 3 +class TestSeedSpecificFormats(BaseSeedSpecificFormats): + pass + + class BaseTestEmptySeed: @pytest.fixture(scope="class") def project_config_update(self): diff --git a/dbt/tests/adapter/store_test_failures_tests/test_store_test_failures.py b/dbt/tests/adapter/store_test_failures_tests/test_store_test_failures.py index bcff69e2..450ed719 100644 --- a/dbt/tests/adapter/store_test_failures_tests/test_store_test_failures.py +++ b/dbt/tests/adapter/store_test_failures_tests/test_store_test_failures.py @@ -118,7 +118,7 @@ def run_tests_store_failures_and_assert(self, project): ) -class TestStoreTestFailures(StoreTestFailuresBase): +class BaseStoreTestFailures(StoreTestFailuresBase): @pytest.fixture(scope="function") def clean_up(self, project): yield @@ -150,3 +150,7 @@ def column_type_overrides(self): def test__store_and_assert(self, project, clean_up): self.run_tests_store_one_failure(project) self.run_tests_store_failures_and_assert(project) + + +class TestStoreTestFailures(BaseStoreTestFailures): + pass From a0142196aa1bd334da449bda9b5117efe7010b07 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Fri, 16 Feb 2024 13:54:38 -0500 Subject: [PATCH 2/3] changelog --- .changes/unreleased/Fixes-20240216-135420.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240216-135420.yaml diff --git a/.changes/unreleased/Fixes-20240216-135420.yaml b/.changes/unreleased/Fixes-20240216-135420.yaml new file mode 100644 index 00000000..a04cd26b --- /dev/null +++ b/.changes/unreleased/Fixes-20240216-135420.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Make all adapter zone tests importable by removing "Test" prefix +time: 2024-02-16T13:54:20.411864-05:00 +custom: + Author: mikealfare + Issue: "93" From 815eb106dfd3b009074660d38406e2b81420b136 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Fri, 16 Feb 2024 19:02:25 -0500 Subject: [PATCH 3/3] move referenced files into fixtures --- dbt/tests/adapter/hooks/data/seed_model.sql | 17 --------- dbt/tests/adapter/hooks/data/seed_run.sql | 17 --------- dbt/tests/adapter/hooks/fixtures.py | 40 +++++++++++++++++++++ dbt/tests/adapter/hooks/test_model_hooks.py | 4 +-- dbt/tests/adapter/hooks/test_run_hooks.py | 3 +- 5 files changed, 43 insertions(+), 38 deletions(-) delete mode 100644 dbt/tests/adapter/hooks/data/seed_model.sql delete mode 100644 dbt/tests/adapter/hooks/data/seed_run.sql diff --git a/dbt/tests/adapter/hooks/data/seed_model.sql b/dbt/tests/adapter/hooks/data/seed_model.sql deleted file mode 100644 index af63d56b..00000000 --- a/dbt/tests/adapter/hooks/data/seed_model.sql +++ /dev/null @@ -1,17 +0,0 @@ - -drop table if exists {schema}.on_model_hook; - -create table {schema}.on_model_hook ( - test_state TEXT, -- start|end - target_dbname TEXT, - target_host TEXT, - target_name TEXT, - target_schema TEXT, - target_type TEXT, - target_user TEXT, - target_pass TEXT, - target_threads INTEGER, - run_started_at TEXT, - invocation_id TEXT, - thread_id TEXT -); diff --git a/dbt/tests/adapter/hooks/data/seed_run.sql b/dbt/tests/adapter/hooks/data/seed_run.sql deleted file mode 100644 index 9872df46..00000000 --- a/dbt/tests/adapter/hooks/data/seed_run.sql +++ /dev/null @@ -1,17 +0,0 @@ - -drop table if exists {schema}.on_run_hook; - -create table {schema}.on_run_hook ( - test_state TEXT, -- start|end - target_dbname TEXT, - target_host TEXT, - target_name TEXT, - target_schema TEXT, - target_type TEXT, - target_user TEXT, - target_pass TEXT, - target_threads INTEGER, - run_started_at TEXT, - invocation_id TEXT, - thread_id TEXT -); diff --git a/dbt/tests/adapter/hooks/fixtures.py b/dbt/tests/adapter/hooks/fixtures.py index c9f1e7da..6f44aea6 100644 --- a/dbt/tests/adapter/hooks/fixtures.py +++ b/dbt/tests/adapter/hooks/fixtures.py @@ -360,3 +360,43 @@ 4,5,6 7,8,9 """ + + +tables__on_model_hook = """ +drop table if exists {schema}.on_model_hook; + +create table {schema}.on_model_hook ( + test_state TEXT, -- start|end + target_dbname TEXT, + target_host TEXT, + target_name TEXT, + target_schema TEXT, + target_type TEXT, + target_user TEXT, + target_pass TEXT, + target_threads INTEGER, + run_started_at TEXT, + invocation_id TEXT, + thread_id TEXT +); +""" + + +tables__on_run_hook = """ +drop table if exists {schema}.on_run_hook; + +create table {schema}.on_run_hook ( + test_state TEXT, -- start|end + target_dbname TEXT, + target_host TEXT, + target_name TEXT, + target_schema TEXT, + target_type TEXT, + target_user TEXT, + target_pass TEXT, + target_threads INTEGER, + run_started_at TEXT, + invocation_id TEXT, + thread_id TEXT +); +""" diff --git a/dbt/tests/adapter/hooks/test_model_hooks.py b/dbt/tests/adapter/hooks/test_model_hooks.py index 5f603d7c..6f90b93d 100644 --- a/dbt/tests/adapter/hooks/test_model_hooks.py +++ b/dbt/tests/adapter/hooks/test_model_hooks.py @@ -70,10 +70,10 @@ """ -class BaseTestPrePost(object): +class BaseTestPrePost: @pytest.fixture(scope="class", autouse=True) def setUp(self, project): - project.run_sql_file(project.test_data_dir / Path("seed_model.sql")) + project.run_sql(fixtures.tables__on_model_hook) def get_ctx_vars(self, state, count, project): fields = [ diff --git a/dbt/tests/adapter/hooks/test_run_hooks.py b/dbt/tests/adapter/hooks/test_run_hooks.py index 89565c70..656c84f6 100644 --- a/dbt/tests/adapter/hooks/test_run_hooks.py +++ b/dbt/tests/adapter/hooks/test_run_hooks.py @@ -1,5 +1,4 @@ import os -from pathlib import Path import pytest @@ -10,7 +9,7 @@ class BasePrePostRunHooks: @pytest.fixture(scope="function") def setUp(self, project): - project.run_sql_file(project.test_data_dir / Path("seed_run.sql")) + project.run_sql(fixtures.tables__on_run_hook) project.run_sql(f"drop table if exists { project.test_schema }.schemas") project.run_sql(f"drop table if exists { project.test_schema }.db_schemas") os.environ["TERM_TEST"] = "TESTING"