https://prefect.io logo
l

Lukáš Pravda

06/27/2023, 4:02 PM
Hello community, I was wondering if anyone could shed a light into how can one mock a task run (in prefect 1.x) when testing flow run-end-to-end. I’m aware of this. But I could not decipher how tod o it properly even in a simple case. Given a simple flow definition:
Copy code
from prefect import Flow, task, Parameter

@task
def add(a, b):
    return a + b

with Flow("test") as flow:
    a = Parameter(name="a")
    b = Parameter(name="b")
    
    add(a,b)
how does write a test case to mock
add()
task? What I’d normally do would be this: but this does not work
Copy code
@patch.object(flow_module.add, "run")
    def test_foo(self, mock):
        flow_module.flow.run(parameters={"a": 1, "b": 2})

        assert mock.call_count == 1
Advices, suggestions? Please dont say move to prefect 2.0 🙂 Thank you!