ferruzzi commented on code in PR #39496:
URL: https://github.com/apache/airflow/pull/39496#discussion_r1594784899
##########
tests/utils/test_log_handlers.py:
##########
@@ -317,43 +317,52 @@ def
test__read_for_celery_executor_fallbacks_to_worker(self, create_task_instanc
"""Test for executors which do not have `get_task_log` method, it
fallbacks to reading
log from worker if and only if remote logs aren't found"""
executor_name = "CeleryExecutor"
-
- ti = create_task_instance(
- dag_id="dag_for_testing_celery_executor_log_read",
- task_id="task_for_testing_celery_executor_log_read",
- run_type=DagRunType.SCHEDULED,
- execution_date=DEFAULT_DATE,
- )
- ti.state = TaskInstanceState.RUNNING
- ti.try_number = 2
- with conf_vars({("core", "executor"): executor_name}):
- reload(executor_loader)
- fth = FileTaskHandler("")
-
- fth._read_from_logs_server = mock.Mock()
- fth._read_from_logs_server.return_value = ["this message"],
["this\nlog\ncontent"]
- actual = fth._read(ti=ti, try_number=2)
- fth._read_from_logs_server.assert_called_once()
- assert actual == ("*** this message\nthis\nlog\ncontent",
{"end_of_log": False, "log_pos": 16})
-
- # Previous try_number should return served logs when remote logs
aren't implemented
- fth._read_from_logs_server = mock.Mock()
- fth._read_from_logs_server.return_value = ["served logs
try_number=1"], ["this\nlog\ncontent"]
- actual = fth._read(ti=ti, try_number=1)
- fth._read_from_logs_server.assert_called_once()
- assert actual == (
- "*** served logs try_number=1\nthis\nlog\ncontent",
- {"end_of_log": True, "log_pos": 16},
+ # Reading logs from worker should occur when the task is either
running, deferred, or up for retry.
+ for state in (TaskInstanceState.RUNNING, TaskInstanceState.DEFERRED,
TaskInstanceState.UP_FOR_RETRY):
Review Comment:
If you are wrapping the entire test in a "for" loop, you should consider
making it a parameterized test. Something like this should replace your for
loop without any other changes needed, and provide more useful information if
one of them starts failing.
```suggestion
@pytest.mark.parametrize(
"state",
[
pytest.param(TaskInstanceState.RUNNING, id="running"),
pytest.param(TaskInstanceState.DEFERRED, id="deferred"),
pytest.param(TaskInstanceState.UP_FOR_RETRY, id="retry")
]
def test__read_for_celery_executor_fallbacks_to_worker(self,
create_task_instance):
```
--
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]