Are there any examples of running local unit tests...
# prefect-server
b
Are there any examples of running local unit tests to verify your tasks are working? I'd like to have some pre-deployment checks in my GitHub actions.
a
So far we have: • this page about unit-testing flows and tasks • this discussion about CI/CD in Prefect with several examples from other users
b
Thank you. I've got my first flow reading in to my test with
extract_flow_from_file
but I'm struggling to figure out how I might override a default parameter before calling it with
.run()
. Is there a way to do that?
a
for sure, but can you explain what exactly do you mean? Parameter defaults can be provided in their definition and when triggering a flow run, you can overwrite them e.g. the
create_flow_run
task (or mutation) allow you to pass your custom parameter values
b
Ah. create_flow_run must be what I need! I'll try it. Thank you.
👍 1
Here is the overly simplistic idea I'm trying that is failing. Clearly I'm missing something obvious about how to approach this.
Copy code
flow = extract_flow_from_file("flow.py")
    assert len(flow.tasks) == 4
    flow.validate()
    create_flow_run(
        flow_id=flow.id,
        flow_name=flow.name,
        parameters={
            "scrapers": ["ia"],
        }
    )
For me, I think the helpful example would be a simple doc that shows "Here's how you import your hello-world.py flow and run it inside a test."
a
yup, you can import your flow object within your tests. Nice that you found it