uranusjr commented on code in PR #28848:
URL: https://github.com/apache/airflow/pull/28848#discussion_r1071018424


##########
kubernetes_tests/test_kubernetes_pod_operator.py:
##########
@@ -141,7 +141,9 @@ def teardown(self) -> None:
         client = hook.core_v1_client
         client.delete_collection_namespaced_pod(namespace="default", 
grace_period_seconds=0)
 
-    def test_do_xcom_push_defaults_false(self):
+    @mock.patch(f"{HOOK_CLASS}.get_connection")
+    def test_do_xcom_push_defaults_false(self, get_connection_mock):
+        get_connection_mock.return_value = 
Connection(conn_id="kubernetes_default")

Review Comment:
   ```suggestion
       @mock.patch(f"{HOOK_CLASS}.get_connection", 
return_value=Connection(conn_id="kubernetes_default"))
       def test_do_xcom_push_defaults_false(self, get_connection_mock):
   ```
   
   I think you can do this instead.
   
   Since this is repeated so may times, it may be a good idea to make this a 
fixture instead:
   
   ```python
   @pytest.fixture()
   def mock_get_connection():
       with mock.patch(f"{HOOK_CLASS}.get_connection", 
return_value=Connection(conn_id="kubernetes_default")):
           yield
   
   @pytest.mark.usefixtures("mock_get_connection")
   def test_do_xcom_push_defaults_false(self):
       ...
   ```



-- 
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