Skip to content

Commit

Permalink
Remove unnecessary logs from test output (#38974)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
potiuk authored Apr 12, 2024
1 parent c450cbf commit 311f2dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/models/test_mappedoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand All @@ -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
Expand Down

0 comments on commit 311f2dd

Please sign in to comment.