Using the <patch/task_mock functionality> I'm able...
# ask-the-community
Using the patch/task_mock functionality I'm able to write unit tests to confirm that a workflow calls tasks correctly. Is there a way to test that a workflow calls subworkflows by mocking them, or do unit tests always need to go down to the task level?
you can only mock a task for now. is there any particular reason you want to mock a workflow
Thanks, good to know πŸ‘ The main use case is having unit tests to confirm that a sequence of sub-workflows execute as expected in a top-level workflow, particularly as the top-level workflow contains a conditional for whether a sub-workflow might be run. For example, in the below code snippet, it would be handy being able to have a test like the example at the bottom, to protect against unwanted modifications to the workflow steps or conditionals behaving unexpectedly.
Copy code
def final_task():
    return 5

def no_task():
    return 0

def my_subworkflow() -> int:
    return final_task()

def my_workflow(some_condition: bool) -> int:
    result = (
    return result

def test_my_workflow_invokes_expected_condition(

I believe it’s doable. mind creating an issue. [flyte-core] contributions are welcome
Thanks! Good suggestion, I've added the issue πŸ‘
ah, I came here to ask this same question! We have a workflow with some sub-workflows that call remote entities and do some other side-effecty stuff, and I want to just patch the sub-workflows to test the workflow that calls them. For some reason it worked in flyte 1.2.7 (we were stuck on that version for a long time due to some other dependency stuff) but when I just upgraded to python 3.10/Flyte 1.11, the "mocked" sub-workflows now fail if the underlying remote tasks aren't mocked out. @Charlie Moriarty wondering if you came up with any ad-hoc fix that can be used before that ticket gets tackled?
@Romaine Martin please +1 the issue, or if you can offer / propose a fix
@Romaine Martin Unfortunately we haven't found a workaround as of yet - for the time being we've reduced our test coverage but it would be great to be able to address these missing patches. Here's the link to the issue if you want to keep an eye on it!
The core team at union will get on this in sometime. Sorry higher pri items