https://prefect.io logo
#prefect-community
Title
# prefect-community
e

Emma Rizzi

05/24/2022, 7:17 AM
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

Anna Geller

05/24/2022, 10:58 AM
Do you ask for 1.0 or Prefect 2.0?
e

Emma Rizzi

05/24/2022, 12:16 PM
@Anna Geller im on Prefect 1.0 🙂
a

Anna Geller

05/24/2022, 12:25 PM
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

Emma Rizzi

05/24/2022, 1:23 PM
@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

Kevin Kho

05/24/2022, 2:21 PM
Maybe you can adda handler to that logger? Seems excessive though
5 Views