From 44e14251c31802d146aff1e3bb4bc81c813a838b Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 3 Jan 2025 15:23:36 +0100 Subject: [PATCH] test: Again --- anta/logger.py | 9 +-------- tests/units/test_logger.py | 9 +++------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/anta/logger.py b/anta/logger.py index 578cb55ff..a3ef52864 100644 --- a/anta/logger.py +++ b/anta/logger.py @@ -86,15 +86,8 @@ def setup_logging(level: LogLevel = Log.INFO, file: Path | None = None) -> None: def _get_file_handler(logger_instance: logging.Logger, file: Path) -> logging.FileHandler | None: """Return the FileHandler if present.""" - # ruff: noqa: T201 - for handler in logger_instance.handlers: - if isinstance(handler, logging.FileHandler): - print(handler.baseFilename) - print(Path(handler.baseFilename)) - print(file) - return ( - next((handler for handler in logger_instance.handlers if isinstance(handler, logging.FileHandler) and handler.baseFilename == str(file)), None) + next((handler for handler in logger_instance.handlers if isinstance(handler, logging.FileHandler) and Path(handler.baseFilename) == file), None) if logger_instance.hasHandlers() else None ) diff --git a/tests/units/test_logger.py b/tests/units/test_logger.py index 1cb97c9bf..a8f0bc794 100644 --- a/tests/units/test_logger.py +++ b/tests/units/test_logger.py @@ -6,24 +6,21 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING +from pathlib import Path from unittest.mock import patch import pytest from anta.logger import Log, LogLevel, _get_file_handler, _get_rich_handler, anta_log_exception, exc_to_str, setup_logging, tb_to_str -if TYPE_CHECKING: - from pathlib import Path - @pytest.mark.parametrize( ("level", "path", "debug_value"), [ pytest.param(Log.INFO, None, False, id="INFO no file"), pytest.param(Log.DEBUG, None, False, id="DEBUG no file"), - pytest.param(Log.INFO, "/tmp/file.log", False, id="INFO file"), - pytest.param(Log.DEBUG, "/tmp/file.log", False, id="DEBUG file"), + pytest.param(Log.INFO, Path("/tmp/file.log"), False, id="INFO file"), + pytest.param(Log.DEBUG, Path("/tmp/file.log"), False, id="DEBUG file"), pytest.param(Log.INFO, None, True, id="INFO no file __DEBUG__ set"), pytest.param(Log.DEBUG, None, True, id="INFO no file __DEBUG__ set"), ],