From e43b624c6ef0dbdbe09f77d3a37a04777d2d4d90 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Fri, 26 Apr 2024 14:54:23 -0700 Subject: [PATCH] Hardcode dbt version for `project` fixture in repository unit tests Letting the dbt version be dynamic in the project fixture previously was causing some tests to break whenever the version of dbt actually got updated, which isn't great. It'd be super annoying to have to always update tests affected by this. To get around this we've gone and hard coded the dbt version in the profile. The alternative was to interpolate the version during comparison during the relevant tests, which felt less appealing. --- tests/unit/config/test_project.py | 2 +- tests/unit/utils/project.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/config/test_project.py b/tests/unit/config/test_project.py index f51719c7e33..a4aa63f9585 100644 --- a/tests/unit/config/test_project.py +++ b/tests/unit/config/test_project.py @@ -45,7 +45,7 @@ def test_fixture_paths(self, project: Project): def test__str__(self, project: Project): assert ( str(project) - == "{'name': 'test_project', 'version': 1.0, 'project-root': 'doesnt/actually/exist', 'profile': 'test_profile', 'model-paths': ['models'], 'macro-paths': ['macros'], 'seed-paths': ['seeds'], 'test-paths': ['tests'], 'analysis-paths': ['analyses'], 'docs-paths': ['docs'], 'asset-paths': ['assets'], 'target-path': 'target', 'snapshot-paths': ['snapshots'], 'clean-targets': ['target'], 'log-path': 'path/to/project/logs', 'quoting': {'database': True, 'schema': True, 'identifier': True}, 'models': {}, 'on-run-start': [], 'on-run-end': [], 'dispatch': [{'macro_namespace': 'dbt_utils', 'search_order': ['test_project', 'dbt_utils']}], 'seeds': {}, 'snapshots': {}, 'sources': {}, 'data_tests': {}, 'unit_tests': {}, 'metrics': {}, 'semantic-models': {}, 'saved-queries': {}, 'exposures': {}, 'vars': {}, 'require-dbt-version': ['=1.8.0-b3'], 'restrict-access': False, 'dbt-cloud': {}, 'query-comment': {'comment': \"\\n{%- set comment_dict = {} -%}\\n{%- do comment_dict.update(\\n app='dbt',\\n dbt_version=dbt_version,\\n profile_name=target.get('profile_name'),\\n target_name=target.get('target_name'),\\n) -%}\\n{%- if node is not none -%}\\n {%- do comment_dict.update(\\n node_id=node.unique_id,\\n ) -%}\\n{% else %}\\n {# in the node context, the connection name is the node_id #}\\n {%- do comment_dict.update(connection_name=connection_name) -%}\\n{%- endif -%}\\n{{ return(tojson(comment_dict)) }}\\n\", 'append': False, 'job-label': False}, 'packages': []}" + == "{'name': 'test_project', 'version': 1.0, 'project-root': 'doesnt/actually/exist', 'profile': 'test_profile', 'model-paths': ['models'], 'macro-paths': ['macros'], 'seed-paths': ['seeds'], 'test-paths': ['tests'], 'analysis-paths': ['analyses'], 'docs-paths': ['docs'], 'asset-paths': ['assets'], 'target-path': 'target', 'snapshot-paths': ['snapshots'], 'clean-targets': ['target'], 'log-path': 'path/to/project/logs', 'quoting': {'database': True, 'schema': True, 'identifier': True}, 'models': {}, 'on-run-start': [], 'on-run-end': [], 'dispatch': [{'macro_namespace': 'dbt_utils', 'search_order': ['test_project', 'dbt_utils']}], 'seeds': {}, 'snapshots': {}, 'sources': {}, 'data_tests': {}, 'unit_tests': {}, 'metrics': {}, 'semantic-models': {}, 'saved-queries': {}, 'exposures': {}, 'vars': {}, 'require-dbt-version': ['=0.0.0'], 'restrict-access': False, 'dbt-cloud': {}, 'query-comment': {'comment': \"\\n{%- set comment_dict = {} -%}\\n{%- do comment_dict.update(\\n app='dbt',\\n dbt_version=dbt_version,\\n profile_name=target.get('profile_name'),\\n target_name=target.get('target_name'),\\n) -%}\\n{%- if node is not none -%}\\n {%- do comment_dict.update(\\n node_id=node.unique_id,\\n ) -%}\\n{% else %}\\n {# in the node context, the connection name is the node_id #}\\n {%- do comment_dict.update(connection_name=connection_name) -%}\\n{%- endif -%}\\n{{ return(tojson(comment_dict)) }}\\n\", 'append': False, 'job-label': False}, 'packages': []}" ) def test_get_selector(self, project: Project): diff --git a/tests/unit/utils/project.py b/tests/unit/utils/project.py index 53bad5214a8..b34e03da494 100644 --- a/tests/unit/utils/project.py +++ b/tests/unit/utils/project.py @@ -1,7 +1,5 @@ import pytest -import dbt.config -import dbt.exceptions from dbt.adapters.contracts.connection import QueryComment from dbt.config.project import Project, RenderComponents, VarProvider from dbt.config.selectors import SelectorConfig @@ -59,7 +57,7 @@ def project(selector_config: SelectorConfig) -> Project: saved_queries={}, exposures={}, vars=VarProvider({}), - dbt_version=[VersionSpecifier.from_version_string(dbt.version.__version__)], + dbt_version=[VersionSpecifier.from_version_string("0.0.0")], packages=PackageConfig([]), manifest_selectors={}, selectors=selector_config,