https://prefect.io logo
Title
a

Aram Panasenco

03/18/2022, 5:16 PM
I'd like to set up a testing framework for testing Prefect flows. The idea is that when someone modifies a Prefect flow in a pull request, an automated DevOps process can launch that flow with certain parameters and somehow test that the flow did what it was supposed to do. I couldn't find anything in the documentation or in Slack. Is there an official testing framework for Prefect flows? If not, what do you all use?
k

Kevin Kho

03/18/2022, 5:34 PM
Have you seen this ? Also, unit tests in the task library are good references also. But if you want to really launch a flow, I think you can use
create_flow_run
and
wait_for_flow_run
with some form of environment separation. Essentially use Prefect also to build out CI/CD 😅
a

Aram Panasenco

03/18/2022, 5:42 PM
I visited that link before, but it felt like testing for the Prefect library itself rather than testing a particular flow. What I really want to do is test whether this particular flow that someone wants to deploy to production is doing what it's supposed to when I run it in a non-production environment first.
create_flow_run
and
wait_for_flow_run
actually look very useful for that purpose. I can create a separate "testing" flow for each main flow that'd call the main flow with test parameters. But I'm guessing there's no library like
pytest
on top of those functions that would streamline the testing process and result reporting...
k

Kevin Kho

03/18/2022, 5:48 PM
There is none because those are API calls under the hood also. Some people use a different tenant for this purposes with agents specifically provisioned for a dev environment. But you can do the same with projects if you only have one tenant. Have you seen this link as well? It might work
👍 1
k

Kyle McChesney

03/18/2022, 6:48 PM
We’ve had a decent amount of success with unit testing the tasks themselves and running that in CI. They are very well isolated from needing a fully fledge flow context etc. We also build/push a new flow version in our development environment on open pull requests. I could see that expanding to trigger an actual flow run.
👀 1