Skip to content
Closed
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
18 changes: 8 additions & 10 deletions airflow-core/tests/unit/utils/test_log_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
import logging.config
import os
import re
from collections.abc import Iterable
from http import HTTPStatus
from importlib import reload
Expand Down Expand Up @@ -106,10 +105,10 @@ def test_default_task_logging_setup(self):
handler = handlers[0]
assert handler.name == FILE_TASK_HANDLER

@pytest.mark.xfail(reason="TODO: Needs to be ported over to the new structlog based logging")
def test_file_task_handler_when_ti_value_is_invalid(self, dag_maker):
def task_callable(ti):
ti.log.info("test")
def task_callable():
logger = logging.getLogger(TASK_LOGGER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use structlog.get_logger instead?

logger.info("test")

with dag_maker("dag_for_testing_file_task_handler", schedule=None):
task = PythonOperator(
Expand Down Expand Up @@ -151,10 +150,10 @@ def task_callable(ti):
# Remove the generated tmp log file.
os.remove(log_filename)

@pytest.mark.xfail(reason="TODO: Needs to be ported over to the new structlog based logging")
def test_file_task_handler(self, dag_maker, session):
def task_callable(ti):
ti.log.info("test")
def task_callable():
logger = logging.getLogger(TASK_LOGGER)
logger.info("test")

with dag_maker("dag_for_testing_file_task_handler", schedule=None, session=session):
PythonOperator(
Expand Down Expand Up @@ -190,12 +189,11 @@ def task_callable(ti):
assert hasattr(file_handler, "read")
log, metadata = file_handler.read(ti, 1)
assert isinstance(metadata, dict)
target_re = re.compile(r"\A\[[^\]]+\] {test_log_handlers.py:\d+} INFO - test\Z")
log_events = events(log)

# We should expect our log line from the callable above to appear in
# the logs we read back

assert any(re.search(target_re, e) for e in events(log)), "Logs were " + str(log)
assert any("test" in event for event in log_events), f"Logs were {log_events}"

# Remove the generated tmp log file.
os.remove(log_filename)
Expand Down
Loading