This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5c524b3c2f Replace `len(mock_calls)` with 
`call_count/assert_called_once` (#28640)
5c524b3c2f is described below

commit 5c524b3c2f9205dd41d3926c267d0d628e3a9ea2
Author: Jed Cunningham <[email protected]>
AuthorDate: Thu Dec 29 15:00:00 2022 -0600

    Replace `len(mock_calls)` with `call_count/assert_called_once` (#28640)
    
    Just easier to read, and in the case of `assert_called_once`, you get
    a better error message.
---
 tests/executors/test_base_executor.py                   | 2 +-
 tests/models/test_taskinstance.py                       | 2 +-
 tests/operators/test_subdag_operator.py                 | 6 +++---
 tests/providers/google/cloud/operators/test_mlengine.py | 2 +-
 tests/providers/samba/hooks/test_samba.py               | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/executors/test_base_executor.py 
b/tests/executors/test_base_executor.py
index 676b6aa581..4d7553710c 100644
--- a/tests/executors/test_base_executor.py
+++ b/tests/executors/test_base_executor.py
@@ -101,7 +101,7 @@ def setup_trigger_tasks(dag_maker):
 def test_trigger_queued_tasks(dag_maker, open_slots):
     executor, _ = setup_trigger_tasks(dag_maker)
     executor.trigger_tasks(open_slots)
-    assert len(executor.execute_async.mock_calls) == open_slots
+    assert executor.execute_async.call_count == open_slots
 
 
 @mark.parametrize("change_state_attempt", range(QUEUEING_ATTEMPTS + 2))
diff --git a/tests/models/test_taskinstance.py 
b/tests/models/test_taskinstance.py
index e80e5032ac..45ea3d75e9 100644
--- a/tests/models/test_taskinstance.py
+++ b/tests/models/test_taskinstance.py
@@ -2569,7 +2569,7 @@ class TestTaskInstance:
         ti.task = task
         with patch.object(TI, "log") as log, pytest.raises(AirflowException):
             ti.run()
-        assert len(log.error.mock_calls) == 1
+        log.error.assert_called_once()
         assert log.error.call_args[0] == ("Task failed with exception",)
         exc_info = log.error.call_args[1]["exc_info"]
         filename = exc_info[2].tb_frame.f_code.co_filename
diff --git a/tests/operators/test_subdag_operator.py 
b/tests/operators/test_subdag_operator.py
index ae6ebf4084..b0b3c922c1 100644
--- a/tests/operators/test_subdag_operator.py
+++ b/tests/operators/test_subdag_operator.py
@@ -166,7 +166,7 @@ class TestSubDagOperator:
             external_trigger=True,
         )
 
-        assert 3 == len(subdag_task._get_dagrun.mock_calls)
+        assert 3 == subdag_task._get_dagrun.call_count
 
     def test_execute_create_dagrun_with_conf(self):
         """
@@ -203,7 +203,7 @@ class TestSubDagOperator:
             external_trigger=True,
         )
 
-        assert 3 == len(subdag_task._get_dagrun.mock_calls)
+        assert 3 == subdag_task._get_dagrun.call_count
 
     def test_execute_dagrun_failed(self):
         """
@@ -253,7 +253,7 @@ class TestSubDagOperator:
         subdag_task.post_execute(context=context)
 
         subdag.create_dagrun.assert_not_called()
-        assert 3 == len(subdag_task._get_dagrun.mock_calls)
+        assert 3 == subdag_task._get_dagrun.call_count
 
     def test_rerun_failed_subdag(self, dag_maker):
         """
diff --git a/tests/providers/google/cloud/operators/test_mlengine.py 
b/tests/providers/google/cloud/operators/test_mlengine.py
index c2ff7d8958..1f3dde89c0 100644
--- a/tests/providers/google/cloud/operators/test_mlengine.py
+++ b/tests/providers/google/cloud/operators/test_mlengine.py
@@ -609,7 +609,7 @@ class 
TestMLEngineTrainingCancelJobOperator(unittest.TestCase):
             delegate_to=None,
             impersonation_chain=None,
         )
-        # Make sure only 'create_job' is invoked on hook instance
+        # Make sure only 'cancel_job' is invoked on hook instance
         assert len(hook_instance.mock_calls) == 1
         hook_instance.cancel_job.assert_called_once_with(
             project_id=self.TRAINING_DEFAULT_ARGS["project_id"], 
job_id=self.TRAINING_DEFAULT_ARGS["job_id"]
diff --git a/tests/providers/samba/hooks/test_samba.py 
b/tests/providers/samba/hooks/test_samba.py
index 06ec32cb48..f6be5b52cd 100644
--- a/tests/providers/samba/hooks/test_samba.py
+++ b/tests/providers/samba/hooks/test_samba.py
@@ -61,7 +61,7 @@ class TestSambaHook:
             cache["foo"] = mock_connection
 
         # Test that the connection was disconnected upon exit.
-        assert len(mock_connection.disconnect.mock_calls) == 1
+        mock_connection.disconnect.assert_called_once()
 
     @pytest.mark.parametrize(
         "name",

Reply via email to