Hi Prefect, Is there some guidance on how to mock...
# ask-community
p
Hi Prefect, Is there some guidance on how to mock flows runs for testing? More specifically, I want to write a test to test my flows end-to-end, however my flow contains subflows started via
StartFlowRun
. This would require having access to a Prefect server when running my tests. I want to avoid running a Prefect Server since this will tremendously slow down and complicate my unit tests. So I was wondering if there are ways to easily mock flow runs without needing access to a Prefect server?
k
Hey @Peter Roelants, do you have a test and you just want to return something in place of
StartFlowRun.run()
? or is it that you want to test the code inside those subflows?
p
I would like to test the code inside those subflows, and any results they might produce.
k
What do you think of something like?
Copy code
from prefect.utilities.storage import extract_flow_from_file

def test_flow(file):
    file_path = os.path.abspath(file)
    flow = extract_flow_from_file(file_path=file_path)
    flow.run()
p
The problem is that I have a
StartFlowRun
task in a parent flow. So if I want to test the full integration of parent flow and child flow, together with any results from the child flow that the parent flow might use, I currently need a server to run.
k
Ohh ok I see what you mean now
Will ask the team
🙏 1