You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/12/13 10:08:24 UTC

[GitHub] [airflow] ashb commented on a change in pull request #6812: [AIRFLOW-6250] handle_failure needs better default for context and test_mode

ashb commented on a change in pull request #6812: [AIRFLOW-6250] handle_failure needs better default for context and test_mode
URL: https://github.com/apache/airflow/pull/6812#discussion_r357570345
 
 

 ##########
 File path: tests/models/test_taskinstance.py
 ##########
 @@ -1348,3 +1348,37 @@ def test_pendulum_template_dates(self):
         self.assertIsInstance(template_context["execution_date"], pendulum.datetime)
         self.assertIsInstance(template_context["next_execution_date"], pendulum.datetime)
         self.assertIsInstance(template_context["prev_execution_date"], pendulum.datetime)
+
+    def test_handle_failure(self):
+        from unittest import mock
+
+        start_date = timezone.datetime(2016, 6, 1)
+        dag = models.DAG(dag_id="test_handle_failure", schedule_interval=None, start_date=start_date)
+
+        with mock.MagicMock() as mock_on_failure_1, mock.MagicMock() as mock_on_retry_1:
+            task1 = DummyOperator(task_id="test_handle_failure_on_failure",
+                                  on_failure_callback=mock_on_failure_1,
+                                  on_retry_callback=mock_on_retry_1,
+                                  dag=dag)
+            ti1 = TI(task=task1, execution_date=start_date)
+            ti1.state = State.FAILED
+            ti1.handle_failure("test failure handling")
+
+        context_arg_1 = mock_on_failure_1.call_args[0][0]
+        assert context_arg_1 and "task_instance" in context_arg_1
+        assert mock_on_retry_1.call_count == 0
 
 Review comment:
   ```suggestion
           mock_on_retry_1.assert_not_called()
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services