Skip to content

What is the correct way to unit test the PythonBranchOperator #45565

Closed Answered by skiedude
skiedude asked this question in Q&A
Discussion options

You must be logged in to vote

Guess this was a case of the rubber duck. I had read over https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html#unit-tests previously, and tried the suggestion of testing a custom operator. However I realized I tried task.run() and not ti.run()

The following changes got the test working again all the way up to 2.10.4

@@ -27,10 +28,10 @@ def create_dag_task_context():
             state=DagRunState.RUNNING,
             run_type=DagRunType.MANUAL
         )
-        task = dag.get_task(task_id)
-        taskinst = dagrun.get_task_instance(task_id)
-        taskinst.task = task
-        context = taskinst.get_template_context()
-        return task, context
-    return _…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by skiedude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant