Skip to content

Commit

Permalink
Remove caplog from Livy tests (apache#46272)
Browse files Browse the repository at this point in the history
Similarly to apache#46263 - there is no real value in keeping tests for
logs in Livy - and caplog tests are known to be super vulnerable
to side-effects from other tests. Since those tests add no value,
we should just remove them without replacement.
  • Loading branch information
potiuk authored Jan 30, 2025
1 parent 0e39f94 commit 8e39da3
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions providers/tests/apache/livy/operators/test_livy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.
from __future__ import annotations

import logging
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -148,32 +147,6 @@ def test_deletion(self, mock_get_batch, mock_post, mock_delete):

mock_delete.assert_called_once_with(BATCH_ID)

@patch(
"airflow.providers.apache.livy.operators.livy.LivyHook.get_batch_state",
return_value=BatchState.SUCCESS,
)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.get_batch_logs", return_value=LOG_RESPONSE)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.post_batch", return_value=BATCH_ID)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.get_batch", return_value=GET_BATCH)
def test_log_dump(self, mock_get_batch, mock_post, mock_get_logs, mock_get, caplog):
task = LivyOperator(
livy_conn_id="livyunittest",
file="sparkapp",
dag=self.dag,
task_id="livy_example",
polling_interval=1,
)
caplog.clear()
with caplog.at_level(level=logging.INFO, logger=task.hook.log.name):
task.execute(context=self.mock_context)

assert "first_line" in caplog.messages
assert "second_line" in caplog.messages
assert "third_line" in caplog.messages

mock_get.assert_called_once_with(BATCH_ID, retry_args=None)
mock_get_logs.assert_called_once_with(BATCH_ID, 0, 100)

@patch(
"airflow.providers.apache.livy.operators.livy.LivyHook.dump_batch_logs",
return_value=None,
Expand Down Expand Up @@ -319,34 +292,6 @@ def test_deletion_deferrable(

mock_delete.assert_called_once_with(BATCH_ID)

@patch(
"airflow.providers.apache.livy.operators.livy.LivyHook.get_batch_state",
return_value=BatchState.SUCCESS,
)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.get_batch_logs", return_value=LOG_RESPONSE)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.post_batch", return_value=BATCH_ID)
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.get_batch", return_value=GET_BATCH)
def test_log_dump_deferrable(self, mock_get_batch, mock_post, mock_get_logs, mock_get, caplog):
task = LivyOperator(
livy_conn_id="livyunittest",
file="sparkapp",
dag=self.dag,
task_id="livy_example",
polling_interval=1,
deferrable=True,
)
caplog.clear()

with caplog.at_level(level=logging.INFO, logger=task.hook.log.name):
task.execute(context=self.mock_context)

assert "first_line" in caplog.messages
assert "second_line" in caplog.messages
assert "third_line" in caplog.messages

mock_get.assert_called_once_with(BATCH_ID, retry_args=None)
mock_get_logs.assert_called_once_with(BATCH_ID, 0, 100)

@patch("airflow.providers.apache.livy.operators.livy.LivyHook.get_batch", return_value={"appId": APP_ID})
@patch("airflow.providers.apache.livy.operators.livy.LivyHook.post_batch", return_value=BATCH_ID)
def test_execute_complete_success(self, mock_post, mock_get):
Expand Down

0 comments on commit 8e39da3

Please sign in to comment.