Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace caplog with patching log property in k8s tests #46273

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions providers/tests/cncf/kubernetes/hooks/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,28 +976,33 @@ async def test_delete_pod(self, lib_method, kube_config_loader):

@pytest.mark.asyncio
@mock.patch(KUBE_API.format("read_namespaced_pod_log"))
async def test_read_logs(self, lib_method, kube_config_loader, caplog):
async def test_read_logs(self, lib_method, kube_config_loader):
lib_method.return_value = self.mock_await_result("2023-01-11 Some string logs...")

hook = AsyncKubernetesHook(
conn_id=None,
in_cluster=False,
config_file=None,
cluster_context=None,
)
await hook.read_logs(
name=POD_NAME,
namespace=NAMESPACE,
)
with mock.patch(
"airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook.log",
new_callable=PropertyMock,
) as log:
await hook.read_logs(
name=POD_NAME,
namespace=NAMESPACE,
)

lib_method.assert_called_once()
lib_method.assert_called_with(
name=POD_NAME,
namespace=NAMESPACE,
follow=False,
timestamps=True,
)
assert "Container logs from 2023-01-11 Some string logs..." in caplog.text
lib_method.assert_called_once()
lib_method.assert_called_with(
name=POD_NAME,
namespace=NAMESPACE,
follow=False,
timestamps=True,
)
log.return_value.info.assert_called_with(
"Container logs from %s", "2023-01-11 Some string logs..."
)

@pytest.mark.asyncio
@mock.patch(KUBE_BATCH_API.format("read_namespaced_job_status"))
Expand Down