Hello! I'm trying to implement some unit tests for...
# prefect-community
e
Hello! I'm trying to implement some unit tests for tasks, supposed to run with pytest in gitlab ci Problem is, some tasks use prefect logger which is not available in test environment Is there a recommended way to perform tasks unit test ? I thought about using a environment variable to detect if the code is executed in a flow context, I didn't find one already defined by prefect in the docs
a
Do you ask for 1.0 or Prefect 2.0?
e
@Anna Geller im on Prefect 1.0 🙂
a
in that case, I don't know the answer here, sorry - you'd need to somehow mock the Prefect logger? You could check how this is handled in Prefect tests in the core library for 1.0. By briefly browsing through:
Copy code
from prefect.utilities.logging import prefect_logger
I found that you may grab "prefect-test-logger" instead of "prefect" logger using:
Copy code
configure_logging(testing=True)
e
@Anna Geller i'll dig into this thanks! Although, I don't need the logger inside my tests, so i could just have an if statement checking if the code is executed in test or flow environment and call the logger accordingly
k
Maybe you can adda handler to that logger? Seems excessive though