Skip to content

Commit

Permalink
Run tests for Providers also for Airflow 2.8
Browse files Browse the repository at this point in the history
This is a follow-up on apache#39513 to add support for running Provider
tests against Airlfow 2.8 installed from PyPI.

The changes include simplifying specification of providers to exclude
for each version and adds a warning for a problem detected in common.io
provider where common.io FileTransfer operator does not work for
Airflow 2.8.
  • Loading branch information
potiuk committed May 19, 2024
1 parent 4c5f6b0 commit 93722c1
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions tests/providers/google/cloud/log/test_stackdriver_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
from google.cloud.logging import Resource
from google.cloud.logging_v2.types import ListLogEntriesRequest, ListLogEntriesResponse, LogEntry

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.providers.google.cloud.log.stackdriver_task_handler import StackdriverTaskHandler
from airflow.utils import timezone
from airflow.utils.state import TaskInstanceState
from tests.test_utils.compat import AIRFLOW_V_2_9_PLUS
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_dags, clear_db_runs

Expand Down Expand Up @@ -81,21 +83,26 @@ def test_should_use_configured_log_name(mock_client, mock_get_creds_and_project_
mock_get_creds_and_project_id.return_value = ("creds", "project_id")

try:
with conf_vars(
{
("logging", "remote_logging"): "True",
("logging", "remote_base_log_folder"): "stackdriver://host/path",
}
):
importlib.reload(airflow_local_settings)
settings.configure_logging()

logger = logging.getLogger("airflow.task")
handler = logger.handlers[0]
assert isinstance(handler, StackdriverTaskHandler)
with mock.patch.object(handler, "transport_type") as transport_type_mock:
logger.error("foo")
transport_type_mock.assert_called_once_with(mock_client.return_value, "path")
# this is needed for Airflow 2.8 and below where default settings are triggering warning on
# extra "name" in the configuration of stackdriver handler. As of Airflow 2.9 this warning is not
# emitted.
expected_warnings = () if AIRFLOW_V_2_9_PLUS else (RemovedInAirflow3Warning,)
with pytest.warns(expected_warning=expected_warnings):
with conf_vars(
{
("logging", "remote_logging"): "True",
("logging", "remote_base_log_folder"): "stackdriver://host/path",
}
):
importlib.reload(airflow_local_settings)
settings.configure_logging()

logger = logging.getLogger("airflow.task")
handler = logger.handlers[0]
assert isinstance(handler, StackdriverTaskHandler)
with mock.patch.object(handler, "transport_type") as transport_type_mock:
logger.error("foo")
transport_type_mock.assert_called_once_with(mock_client.return_value, "path")
finally:
importlib.reload(airflow_local_settings)
settings.configure_logging()
Expand Down

0 comments on commit 93722c1

Please sign in to comment.