From e36333c2620d140fc154617dac3283f7d9b6cf9c Mon Sep 17 00:00:00 2001 From: elzette-van-rensburg Date: Wed, 3 Apr 2024 10:39:34 +0100 Subject: [PATCH] Weird tests not running --- conftest.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ dbt_project.yml | 2 +- packages.yml | 6 +-- 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 conftest.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..e7d9d198b --- /dev/null +++ b/conftest.py @@ -0,0 +1,98 @@ +import pytest +import os + +pytest_plugins = ["dbt.tests.fixtures.project"] + + +def pytest_addoption(parser): + parser.addoption("--profile", action="store", default="postgres", type=str) + + +# Using @pytest.mark.skip_profile('postgres') uses the 'skip_by_profile_type' +# autouse fixture below +def pytest_configure(config): + config.addinivalue_line( + "markers", + "skip_profile(profile): skip test for the given profile", + ) + config.addinivalue_line( + "markers", + "only_profile(profile): only test the given profile", + ) + + +@pytest.fixture(scope="session") +def dbt_profile_target(request): + profile_type = request.config.getoption("--profile") + if profile_type == "postgres": + target = postgres_target() + elif profile_type == "redshift": + target = redshift_target() + elif profile_type == "snowflake": + target = snowflake_target() + elif profile_type == "bigquery": + target = bigquery_target() + else: + raise ValueError(f"Invalid profile type '{profile_type}'") + return target + + +def postgres_target(): + return { + "type": "postgres", + "host": os.getenv('POSTGRES_TEST_HOST'), + "user": os.getenv('POSTGRES_TEST_USER'), + "pass": os.getenv('POSTGRES_TEST_PASS'), + "port": int(os.getenv('POSTGRES_TEST_PORT')), + "dbname": os.getenv('POSTGRES_TEST_DBNAME'), + } + + +def redshift_target(): + return { + "type": "redshift", + "host": os.getenv('REDSHIFT_TEST_HOST'), + "user": os.getenv('REDSHIFT_TEST_USER'), + "pass": os.getenv('REDSHIFT_TEST_PASS'), + "port": int(os.getenv('REDSHIFT_TEST_PORT')), + "dbname": os.getenv('REDSHIFT_TEST_DBNAME'), + } + + +def bigquery_target(): + return { + "type": "bigquery", + "method": "service-account", + "keyfile": os.getenv('BIGQUERY_SERVICE_KEY_PATH'), + "project": os.getenv('BIGQUERY_TEST_DATABASE'), + } + + +def snowflake_target(): + return { + "type": "snowflake", + "account": os.getenv('SNOWFLAKE_TEST_ACCOUNT'), + "user": os.getenv('SNOWFLAKE_TEST_USER'), + "password": os.getenv('SNOWFLAKE_TEST_PASSWORD'), + "role": os.getenv('SNOWFLAKE_TEST_ROLE'), + "database": os.getenv('SNOWFLAKE_TEST_DATABASE'), + "warehouse": os.getenv('SNOWFLAKE_TEST_WAREHOUSE'), + } + + +@pytest.fixture(autouse=True) +def skip_by_profile_type(request): + profile_type = request.config.getoption("--profile") + if request.node.get_closest_marker("skip_profile"): + for skip_profile_type in request.node.get_closest_marker("skip_profile").args: + if skip_profile_type == profile_type: + pytest.skip("skipped on '{profile_type}' profile") + + +@pytest.fixture(autouse=True) +def only_profile_type(request): + profile_type = request.config.getoption("--profile") + if request.node.get_closest_marker("only_profile"): + for only_profile_type in request.node.get_closest_marker("only_profile").args: + if only_profile_type != profile_type: + pytest.skip("skipped on '{profile_type}' profile") diff --git a/dbt_project.yml b/dbt_project.yml index 1fb8ada90..c09f70575 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -13,7 +13,7 @@ snapshot-paths: ["jaffle_shop/snapshots"] target-path: "target" clean-targets: - "target" - - "dbt_modules" + - "dbt_packages" - "logs" require-dbt-version: [">=1.0.0", "<2.0.0"] diff --git a/packages.yml b/packages.yml index 81ec273e5..6307c58df 100644 --- a/packages.yml +++ b/packages.yml @@ -1,9 +1,9 @@ packages: - package: dbt-labs/dbt_utils - version: 0.8.6 + version: 1.1.1 - package: dbt-labs/spark_utils version: 0.3.0 - package: dbt-labs/codegen - version: 0.7.0 + version: 0.12.1 - package: dbt-labs/dbt_project_evaluator - version: 0.1.3 \ No newline at end of file + version: 0.6.2 \ No newline at end of file