Skip to content

Allowing exclusions to be passed through to the test tasks#2006

Open
anyapriya wants to merge 6 commits intoastronomer:mainfrom
anyapriya:passing_exclusions_to_test_tasks
Open

Allowing exclusions to be passed through to the test tasks#2006
anyapriya wants to merge 6 commits intoastronomer:mainfrom
anyapriya:passing_exclusions_to_test_tasks

Conversation

@anyapriya
Copy link
Copy Markdown
Contributor

@anyapriya anyapriya commented Sep 26, 2025

Description

Previously, exclusions were not being passed through to test tasks when using test behavior of after each or after all. This meant that if you were trying to exclude unit tests or a specific test, you were unable to do so easily without a workaround of also passing the exclusion into the operator args.

While this would be great to also do something similar with the select or selector (ex. select model A and test 2), I think it would be too complex to get the unions / intersections correct. I added documentation about this limitation so it's at least more clear.

Related Issue(s)

Closes #1763
Closes #1865

Breaking Change?

No

Checklist

  • I have made corresponding changes to the documentation (if required)
  • I have added tests that prove my fix is effective or that my feature works

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 26, 2025

Deploy Preview for sunny-pastelito-5ecb04 canceled.

Name Link
🔨 Latest commit 43a2464
🔍 Latest deploy log https://app.netlify.com/projects/sunny-pastelito-5ecb04/deploys/68ef9aba62c41c0008317553

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables exclusions to be passed through to test tasks for all test behaviors (after_each, after_all), allowing users to exclude specific tests or resource types without requiring workarounds. Previously, exclusions only worked with certain test behaviors.

  • Added exclusions parameter to test task creation functions
  • Updated test task metadata creation to include exclusions from render config
  • Added comprehensive test coverage for exclusion behavior with different test scenarios

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
cosmos/airflow/graph.py Added exclusions parameter passing and deepcopy usage for render config attributes
tests/test_converter.py Added integration test validating exclusion behavior across different test scenarios
tests/airflow/test_graph.py Updated test to include exclude parameter in expected metadata
docs/configuration/selecting-excluding.rst Added documentation explaining exclusion behavior with test tasks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

detached_from_parent = detached_from_parent or {}
task_owner = ""

task_args["exclude"] = deepcopy(exclusions)
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exclusions parameter can be None, but deepcopy(None) will return None. This should be handled explicitly to ensure task_args['exclude'] is always a list or None consistently.

Suggested change
task_args["exclude"] = deepcopy(exclusions)
task_args["exclude"] = deepcopy(exclusions) if exclusions is not None else None

Copilot uses AI. Check for mistakes.
node: DbtNode,
task_args: dict[str, str],
detached_from_parent: dict[str, DbtNode] | None = None,
detached_from_parent: dict[str, list[DbtNode]] | None = None,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for detached_from_parent has changed from dict[str, DbtNode] to dict[str, list[DbtNode]] but this appears to be unrelated to the exclusions feature. This could be a breaking change that should be documented or handled separately.

Copilot uses AI. Check for mistakes.
@@ -128,8 +128,9 @@
on_warning_callback: Callable[..., Any] | None = None,
node: DbtNode | None = None,
render_config: RenderConfig | None = None,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for detached_from_parent has changed from dict[str, DbtNode] to dict[str, list[DbtNode]] but this appears to be unrelated to the exclusions feature. This could be a breaking change that should be documented or handled separately.

Suggested change
render_config: RenderConfig | None = None,
render_config: RenderConfig | None = None,
# BREAKING CHANGE: The type of detached_from_parent has changed from dict[str, DbtNode] to dict[str, list[DbtNode]]

Copilot uses AI. Check for mistakes.
test_indirect_selection: TestIndirectSelection = TestIndirectSelection.EAGER,
on_warning_callback: Callable[..., Any] | None = None,
detached_from_parent: dict[str, DbtNode] | None = None,
detached_from_parent: dict[str, list[DbtNode]] | None = None,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for detached_from_parent has changed from dict[str, DbtNode] to dict[str, list[DbtNode]] but this appears to be unrelated to the exclusions feature. This could be a breaking change that should be documented or handled separately.

Copilot uses AI. Check for mistakes.
normalize_task_id: Callable[..., Any] | None = None,
normalize_task_display_name: Callable[..., Any] | None = None,
detached_from_parent: dict[str, DbtNode] | None = None,
detached_from_parent: dict[str, list[DbtNode]] | None = None,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for detached_from_parent has changed from dict[str, DbtNode] to dict[str, list[DbtNode]] but this appears to be unrelated to the exclusions feature. This could be a breaking change that should be documented or handled separately.

Suggested change
detached_from_parent: dict[str, list[DbtNode]] | None = None,
detached_from_parent: dict[str, DbtNode] | None = None,

Copilot uses AI. Check for mistakes.
"--select",
"combined_model",
"--exclude",
"resource_type:unit_test custom_test_combined_model_combined_model_",
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded test name 'custom_test_combined_model_combined_model_' is repeated multiple times. Consider extracting this to a variable to improve maintainability.

Copilot uses AI. Check for mistakes.
"--select",
"model_a",
"--exclude",
"resource_type:unit_test custom_test_combined_model_combined_model_",
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded test name 'custom_test_combined_model_combined_model_' is repeated multiple times. Consider extracting this to a variable to improve maintainability.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.78%. Comparing base (6a9b0bb) to head (4f1ba71).
⚠️ Report is 241 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2006   +/-   ##
=======================================
  Coverage   97.78%   97.78%           
=======================================
  Files          91       91           
  Lines        5862     5862           
=======================================
  Hits         5732     5732           
  Misses        130      130           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 4, 2025

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed and removed stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed labels Dec 4, 2025
@tatiana tatiana self-assigned this Dec 22, 2025
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jan 25, 2026
@tatiana tatiana added this to the Cosmos 1.14.0 milestone Jan 29, 2026
@github-actions github-actions bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 5, 2026
@github-actions
Copy link
Copy Markdown

This PR was closed because it has been inactive for 10 days since being marked as stale.

@github-actions github-actions bot closed this Mar 16, 2026
@tatiana tatiana reopened this Mar 18, 2026
@tatiana tatiana requested review from a team, corsettigyg, dwreeves and jbandoro as code owners March 18, 2026 10:10
@tatiana tatiana requested review from pankajkoti and tatiana March 18, 2026 10:10
@github-actions github-actions bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 22, 2026
@tatiana tatiana modified the milestones: Cosmos 1.14.0, Cosmos 1.15.0 Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] exclude=["resource_type:unit_test"] not being passed [Bug] Excluding unit tests from DbtTaskGroup doesn't work

4 participants