Hi everyone, I am trying to write functional test...
# prefect-community
Hi everyone, I am trying to write functional tests for my code [not prefect] and I want to bypass the prefect decorators [task and flow] so I can write tests for my codes only. Is there any easy way of doing so WITH support of
I have found a nice usage pattern of
Copy code
def my_func(a):
    return a*100

task_my_func = task(my_func)
This then lets me separate out my function for unit tests, and gives me a bit of a reminder when I am using the
in my prefect code that it is delayed and should be called as such. Otherwise, I believe that a
decorated function can still be access. It is something like
Copy code
which might be useful for your unit tests
I dont think this works well with overwriting task params with the usages of
Copy code
from unittest import mock
import logging

def prefect_task_patcher():
    def wrapper(*_args, **_kwargs):
        class PrefectTaskPatcher:
            def __call__(self, *call_args, **call_kwargs):
                return self.fn(*call_args, **call_kwargs)

            def __init__(self, fn):
                self.fn = fn

            def with_options(self, *_options_args, **_options_kwargs):
                return self

        return PrefectTaskPatcher

    return wrapper

mock_task = mock.patch("prefect.task", new_callable=prefect_task_patcher)
mock_logs = mock.patch("prefect.get_run_logger", returns=logging)
I m trying this instead.