cuddly-jelly-27016
06/15/2025, 12:11 AMfrom flytekit import task, workflow
from flytekit.testing import patch as task_patch
from flytekit.testing import workflow_patch
@task
def final_task():
return 5
@task
def no_task():
return 0
@workflow
def my_subworkflow() -> int:
do_some_complicated_tasks()
return final_task()
@workflow
def my_workflow(some_condition: bool) -> int:
result = (
conditional("my_workflow_switch")
.if_(some_condition.is_true())
.then(my_subworkflow())
.else_()
.then(no_task())
)
return result
@workflow_patch(my_subworkflow)
@task_patch(no_task)
def test_my_workflow_invokes_expected_condition(
task_mock,
subworkflow_mock,
):
my_workflow(True)
subworkflow_mock.assert_called_once()
task_mock.assert_not_called()
### Describe alternatives you've considered
Without the ability to patch subworkflows, we would need to write unit tests that have knowledge of each workflow in the chain until we reach the task level for patching - this is doable, but breaks the rules of test isolation.
### Propose: Link/Inline OR Additional context
No response
### Are you sure this issue hasn't been raised already?
• Yes
### Have you read the Code of Conduct?
• Yes
flyteorg/flytecuddly-jelly-27016
06/15/2025, 12:11 AM