uranusjr commented on a change in pull request #20860:
URL: https://github.com/apache/airflow/pull/20860#discussion_r784510220



##########
File path: tests/decorators/test_branch_python.py
##########
@@ -0,0 +1,116 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from airflow.decorators import task
+from airflow.utils.state import State
+
+
+class Test_BranchPythonDecoratedOperator:
+    def test_branch_one(self, dag_maker):
+        @task
+        def dummy_f():
+            pass
+
+        #

Review comment:
       ```suggestion
   ```
   
   Accident?

##########
File path: tests/decorators/test_branch_python.py
##########
@@ -0,0 +1,116 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from airflow.decorators import task
+from airflow.utils.state import State
+
+
+class Test_BranchPythonDecoratedOperator:
+    def test_branch_one(self, dag_maker):
+        @task
+        def dummy_f():
+            pass
+
+        #
+        @task
+        def task_1():
+            pass
+
+        @task
+        def task_2():
+            pass
+
+        @task.branchpython(task_id="branching")
+        def branch_operator():
+            return "task_1"
+
+        with dag_maker():
+            branchoperator = branch_operator()
+            df = dummy_f()
+            task_1 = task_1()
+            task_2 = task_2()
+
+            df.set_downstream(branchoperator)
+            branchoperator.set_downstream(task_1)
+            branchoperator.set_downstream(task_2)
+
+        dr = dag_maker.create_dagrun()
+        df.operator.run(start_date=dr.execution_date, 
end_date=dr.execution_date, ignore_ti_state=True)
+        branchoperator.operator.run(
+            start_date=dr.execution_date, end_date=dr.execution_date, 
ignore_ti_state=True
+        )
+        task_1.operator.run(start_date=dr.execution_date, 
end_date=dr.execution_date, ignore_ti_state=True)
+        task_2.operator.run(start_date=dr.execution_date, 
end_date=dr.execution_date, ignore_ti_state=True)
+        tis = dr.get_task_instances()
+
+        for ti in tis:
+            if ti.task_id == "dummy_f":
+                assert ti.state == State.SUCCESS
+            if ti.task_id == "branching":
+                assert ti.state == State.SUCCESS
+            if ti.task_id == "task_1":
+                assert ti.state == State.SUCCESS
+            if ti.task_id == "task_2":
+                assert ti.state == State.SKIPPED
+
+    def test_branch_two(self, dag_maker):

Review comment:
       These two tests should be merged into one with `@pytest.mark.parametrize`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to