From 96551ca70b50c2a885b93ce12d18b13fc59b3daa Mon Sep 17 00:00:00 2001 From: Cor Date: Sun, 2 Jun 2024 10:57:58 +0200 Subject: [PATCH] Handle dbt flags based on version (#52) * Handle dbt flags based on version See https://github.com/dbt-labs/dbt-core/issues/9183 * Add change log entry --- CHANGELOG.md | 1 + src/pytest_dbt_core/fixtures.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daed1c5..2f44ae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ - Test dbt v1.7 ([PR](https://github.com/godatadriven/pytest-dbt-core/pull/48)) - Make pytest `parser.addoption` type a function ([PR](https://github.com/godatadriven/pytest-dbt-core/pull/51)) +- Handle dbt flags for dbt version 1.6 and higher ## [0.2.3] - 2023-08-25 diff --git a/src/pytest_dbt_core/fixtures.py b/src/pytest_dbt_core/fixtures.py index 89abb87..6cfe19e 100644 --- a/src/pytest_dbt_core/fixtures.py +++ b/src/pytest_dbt_core/fixtures.py @@ -8,12 +8,14 @@ import dbt.tracking import pytest from _pytest.fixtures import SubRequest -from dbt import flags +from dbt import flags, version from dbt.clients.jinja import MacroGenerator +from dbt.config import project from dbt.config.runtime import RuntimeConfig from dbt.context import providers from dbt.contracts.graph.manifest import Manifest from dbt.parser.manifest import ManifestLoader +from dbt.semver import VersionSpecifier from dbt.tracking import User from dbt.adapters.factory import ( # isort:skip @@ -71,7 +73,15 @@ def config(request: SubRequest) -> RuntimeConfig: profile=None, threads=None, ) - flags.set_from_args(args, user_config=None) + + if VersionSpecifier("1", "5", "12") < version.get_installed_version(): + # See https://github.com/dbt-labs/dbt-core/issues/9183 + project_flags = project.read_project_flags( + args.project_dir, args.profiles_dir + ) + flags.set_from_args(args, project_flags) + else: + flags.set_from_args(args, user_config=None) config = RuntimeConfig.from_args(args) return config