ashb commented on a change in pull request #12171:
URL: https://github.com/apache/airflow/pull/12171#discussion_r519653918



##########
File path: tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
##########
@@ -164,3 +164,65 @@ def test_randomize_pod_name(self, mock_client, 
monitor_mock, start_mock):
 
         assert start_mock.call_args[0][0].metadata.name.startswith(name_base)
         assert start_mock.call_args[0][0].metadata.name != name_base
+
+    @mock.patch("airflow.kubernetes.pod_launcher.PodLauncher.start_pod")
+    @mock.patch("airflow.kubernetes.pod_launcher.PodLauncher.monitor_pod")
+    @mock.patch("airflow.kubernetes.kube_client.get_kube_client")
+    def test_describes_pod_on_failure(self, mock_client, monitor_mock, 
start_mock):
+        from airflow.utils.state import State
+
+        name_base = 'test'
+
+        k = KubernetesPodOperator(
+            namespace='default',
+            image="ubuntu:16.04",
+            cmds=["bash", "-cx"],
+            arguments=["echo 10"],
+            labels={"foo": "bar"},
+            name=name_base,
+            task_id="task",
+            in_cluster=False,
+            do_xcom_push=False,
+            cluster_context='default',
+        )
+        monitor_mock.return_value = (State.FAILED, None)
+        failed_pod_status = 'read_pod_namespaced_result'
+        read_namespaced_pod_mock = mock_client.return_value.read_namespaced_pod
+        read_namespaced_pod_mock.return_value = failed_pod_status
+
+        with self.assertRaises(AirflowException) as cm:
+            context = self.create_context(k)
+            k.execute(context=context)
+
+        self.assertEqual(
+            str(cm.exception), "Pod Launching failed: Pod returned a failure: 
" + failed_pod_status
+        )

Review comment:
       ```suggestion
           with self.assertRaisesRegex(
               AirflowException,
               fr'Pod Launching failed: Pod {k.pod.metadata.name} returned a 
failure: {failed_pod_status}',
           ):
               context = self.create_context(k)
               k.execute(context=context)
   ```




----------------------------------------------------------------
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:
[email protected]


Reply via email to