Complete the code to import the base class for custom Airflow operators.
from airflow.operators.[1] import BaseOperator
The BaseOperator class is imported from airflow.operators.base. This is the base class to create custom operators.
Complete the code to define the execute method in a custom operator.
def execute(self, context): self.[1]('Running custom operator logic')
print which outputs to stdout instead of structured task logs.log.info without self..return instead of logging.The execute method runs the operator's logic. Using self.log.info properly logs a message to Airflow's task logger during execution.
Fix the error in the custom operator's init method by completing the super call.
def __init__(self, param1, **kwargs): super().[1](param1=param1, **kwargs)
super().execute instead of __init__.The __init__ method of the parent class must be called to properly initialize the operator.
Complete the code to create a test case that checks if the custom operator runs without errors.
def test_custom_operator(): operator = CustomOperator(task_id='test_task') result = operator.[1]({}) assert result is None
__init__ or run instead of execute.To test a custom operator, instantiate it and call its execute method with an empty context dictionary. For operators that don't return a value, the result is None.
Fill all three blanks to complete a test that mocks the logging inside the custom operator.
import unittest.mock as mock def test_logging_in_operator(): operator = CustomOperator(task_id='log_test') with mock.patch.object(operator, 'log') as mock_log: operator.[1]({}) mock_log.[2].assert_called_with('[3]')
debug instead of info for logging.The test mocks the operator's log instance to check if self.log.info is called with the expected message during execution.