What is the recommended way to test flows that ref...
# prefect-community
t
What is the recommended way to test flows that reference external blocks? For instance this test fails because result_storage is set to a block name.
Copy code
from prefect import flow, get_run_logger, task
from prefect.testing.utilities import prefect_test_harness


def test_flow():
    @task
    def _add(x: int, y: int) -> int:
        get_run_logger().info(f"Adding {x} + {y} in task")
        return x + y

    @flow(persist_result=True, result_storage="s3/mldc-result-storage", result_serializer="json")
    def add(x: int, y: int) -> int:
        get_run_logger().info(f"Adding {x} + {y}")
        result = _add(x, y)
        return result

    with prefect_test_harness():
        assert add(5, 6) == 11
1
r
Since the remote result storage isn't needed for a unit test of the flow function's output, consider using
with_options
to override that setting. In the sample you posted, the last few lines could change to:
Copy code
with prefect_test_harness():
    test_add = add.with_options(result_storage=None)
    assert test_add(5, 6) == 11
2