From 311f2dd3ffc652cec766e55d90345b82dfcadb8a Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Fri, 12 Apr 2024 23:48:07 +0200 Subject: [PATCH] Remove unnecessary logs from test output (#38974) The logs from `fab` and `dag` at info level are useful for PROD but clutter the output for tests. We should set log level for those two modules to warning to avoid that. --- tests/conftest.py | 11 +++++++++++ tests/models/test_mappedoperator.py | 4 ---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6d102e72684c4..45ca9aaea5523 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1145,6 +1145,17 @@ def reset_logging_config(): logging.config.dictConfig(logging_config) +@pytest.fixture(scope="session", autouse=True) +def suppress_info_logs_for_dag_and_fab(): + import logging + + dag_logger = logging.getLogger("airflow.models.dag") + dag_logger.setLevel(logging.WARNING) + + fab_logger = logging.getLogger("airflow.providers.fab.auth_manager.security_manager.override") + fab_logger.setLevel(logging.WARNING) + + @pytest.fixture(scope="module", autouse=True) def _clear_db(request): from tests.test_utils.db import clear_all diff --git a/tests/models/test_mappedoperator.py b/tests/models/test_mappedoperator.py index 41b594aa66b33..e80a629794ae1 100644 --- a/tests/models/test_mappedoperator.py +++ b/tests/models/test_mappedoperator.py @@ -17,7 +17,6 @@ # under the License. from __future__ import annotations -import logging from collections import defaultdict from datetime import timedelta from typing import TYPE_CHECKING @@ -73,8 +72,6 @@ def test_task_mapping_with_dag(): @patch("airflow.models.abstractoperator.AbstractOperator.render_template") def test_task_mapping_with_dag_and_list_of_pandas_dataframe(mock_render_template, caplog): - caplog.set_level(logging.INFO) - class UnrenderableClass: def __bool__(self): raise ValueError("Similar to Pandas DataFrames, this class raises an exception.") @@ -95,7 +92,6 @@ def execute(self, context: Context): mapped = CustomOperator.partial(task_id="task_2").expand(arg=unrenderable_values) task1 >> mapped dag.test() - assert caplog.text.count("[DAG TEST] end task task_id=task_2") == 2 assert ( "Unable to check if the value of type 'UnrenderableClass' is False for task 'task_2', field 'arg'" in caplog.text