QQ how can I assert the state of a dependent flow is successful? I'm running the flow using StartFlowRun
k
Kevin Kho
12/02/2021, 2:05 AM
Hey @Arun Giridharan, use
wait=True
in your
StartFlowRun
a
Arun Giridharan
12/03/2021, 1:42 AM
Hi @Kevin Kho What I have currently is a setup like this.
Copy code
flow_run = StartFlowRun(flow_name="process", project_name="sandbox", wait=true)
with prefect.Flow("download") as flow_download:
fp = "plip"
check = check_file(fp)
download = download_file(check)
run = flow_run(run_name=f"process_{fp}", parameters={'fp': fp})
For my test I would like to
assert
that
process
actually passed. I can verify
download
passed using the
state.is_sucessful()
method. Is there a way to do this for
process
?
k
Kevin Kho
12/03/2021, 1:45 AM
wait=True
will raise the state so if it fails, that task should fail also. Are you checking for success in a state handler?
a
Arun Giridharan
12/03/2021, 1:46 AM
def test_flow_results(monkeypatch):
flow = create_flow()
state = flow.run(
parameters={
...
},
}
)
# Test running the flow does not produce any obvious errors
assert state.is_successful()
Arun Giridharan
12/03/2021, 1:47 AM
I am checking for success for the
flow_download
flow, but I'm not sure how to check for success in the
process
flow?
k
Kevin Kho
12/03/2021, 1:51 AM
Yeah it’s hard cuz under the hood, that task is doing an API call. What I saw one user do is subclass
StartFlowRun
and if it’s running with an env variable, just
raise success
, otherwise actually run the task. So you can do something like that to test it.
Similarly, I think you have to Mock the task itself to test it so that the API call to start a flow run is not triggered. With your Mock, you can
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.