Unit testing#

The decorator and function documented below will help you unit test your Flyte tasks. They are particularly helpful for testing workflows that contain tasks that cannot run locally.

@flytekit.testing.patch#

This is a decorator used for testing.

Parameters:

target (PythonTask | WorkflowBase | ReferenceEntity)

flytekit.testing.task_mock(t)#

Use this method to mock a task declaration. It can mock any Task in Flytekit as long as it has a python native interface associated with it.

The returned object is a MagicMock and allows to perform all such methods. This MagicMock, mocks the execute method on the PythonTask

Usage:

@task
def t1(i: int) -> int:
   pass

with task_mock(t1) as m:
   m.side_effect = lambda x: x
   t1(10)
   # The mock is valid only within this context
Parameters:

t (PythonTask)

Return type:

Generator[MagicMock, None, None]