I want to build a unit test for a function which uses get_current_context in Apache Airflow. The function is used within multiple tasks to create a filename used to read and write to the file from these different tasks.
Here is an example of the function:
def get_filename():
from airflow.operators.python import get_current_context
context = get_current_context()
dag_id = context['dag'].__dict__['_dag_id']
log_time = context['data_interval_start'].strftime("%Y-%m-%d_%H-%M-%S")
log_file = f'/path/logs/{dag_id}/{log_time}.txt'
return log_file
How do I set the context in the unit test so that the function is executable? I don't even know where to begin.