Skip to content

Commit

Permalink
Replace caplog with mocking log methods in wasb tests. (apache#46539)
Browse files Browse the repository at this point in the history
  • Loading branch information
potiuk authored and ambika-garg committed Feb 13, 2025
1 parent f6d4699 commit c420710
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions providers/tests/microsoft/azure/hooks/test_wasb.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,24 +528,26 @@ def test_delete_container(self, mocked_blob_service_client):
mocked_container_client.return_value.delete_container.assert_called()

@pytest.mark.parametrize("exc", [ValueError, RuntimeError])
def test_delete_container_generic_exception(self, exc: type[Exception], caplog):
def test_delete_container_generic_exception(self, exc: type[Exception]):
hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
with mock.patch.object(WasbHook, "_get_container_client") as m:
with (
mock.patch.object(WasbHook, "_get_container_client") as m,
mock.patch.object(hook.log, "error") as log_mock,
):
m.return_value.delete_container.side_effect = exc("FakeException")
caplog.clear()
caplog.set_level("ERROR")
with pytest.raises(exc, match="FakeException"):
hook.delete_container("mycontainer")
assert "Error deleting container: mycontainer" in caplog.text
log_mock.assert_called_with("Error deleting container: %s", "mycontainer")

def test_delete_container_resource_not_found(self, caplog):
def test_delete_container_resource_not_found(self):
hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
with mock.patch.object(WasbHook, "_get_container_client") as m:
with (
mock.patch.object(WasbHook, "_get_container_client") as m,
mock.patch.object(hook.log, "warning") as log_mock,
):
m.return_value.delete_container.side_effect = ResourceNotFoundError("FakeException")
caplog.clear()
caplog.set_level("WARNING")
hook.delete_container("mycontainer")
assert "Unable to delete container mycontainer (not found)" in caplog.text
log_mock.assert_called_with("Unable to delete container %s (not found)", "mycontainer")

@mock.patch.object(WasbHook, "delete_blobs")
def test_delete_single_blob(self, delete_blobs, mocked_blob_service_client):
Expand Down

0 comments on commit c420710

Please sign in to comment.