diff --git a/cosmos/dbt/selector.py b/cosmos/dbt/selector.py index 0e6034a0b..f195f225b 100644 --- a/cosmos/dbt/selector.py +++ b/cosmos/dbt/selector.py @@ -108,6 +108,9 @@ def should_include_node(node_id: str, node: DbtNode) -> bool: visited_nodes.add(node_id) + if node.resource_type == DbtResourceType.TEST: + node.tags = getattr(nodes.get(node.depends_on[0]), "tags", []) + if config.tags: if not (set(config.tags) <= set(node.tags)): return False diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index 3927bbfdd..b36bf92fb 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -504,6 +504,26 @@ def test_update_node_dependency_test_not_exist(): assert nodes.has_test is False +def test_tag_selected_node_test_exist(): + project_config = ProjectConfig( + dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME, manifest_path=SAMPLE_MANIFEST + ) + profile_config = ProfileConfig( + profile_name="test", + target_name="test", + profiles_yml_filepath=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME / "profiles.yml", + ) + dbt_graph = DbtGraph(project=project_config, profile_config=profile_config, select=["tag:test_tag"]) + dbt_graph.load_from_dbt_manifest() + + assert len(dbt_graph.filtered_nodes) > 0 + + for _, node in dbt_graph.filtered_nodes.items(): + assert node.tags == ["test_tag"] + if node.resource_type == DbtResourceType.MODEL: + assert node.has_test is True + + @pytest.mark.integration @pytest.mark.parametrize("load_method", ["load_via_dbt_ls", "load_from_dbt_manifest"]) def test_load_dbt_ls_and_manifest_with_model_version(load_method): diff --git a/tests/sample/manifest.json b/tests/sample/manifest.json index 4150234b8..d0b19c7b6 100644 --- a/tests/sample/manifest.json +++ b/tests/sample/manifest.json @@ -7576,7 +7576,9 @@ "resource_type": "model", "schema": "public", "sources": [], - "tags": [], + "tags": [ + "test_tag" + ], "unique_id": "model.jaffle_shop.customers", "unrendered_config": { "materialized": "table" @@ -7754,7 +7756,9 @@ "resource_type": "model", "schema": "public", "sources": [], - "tags": [], + "tags": [ + "test_tag" + ], "unique_id": "model.jaffle_shop.orders", "unrendered_config": { "materialized": "table"