diff --git a/tests/utils/test_logging.py b/tests/utils/test_logging.py index 5273a71..1eb9638 100644 --- a/tests/utils/test_logging.py +++ b/tests/utils/test_logging.py @@ -1,9 +1,10 @@ import logging -from pytest import LogCaptureFixture +import pytest +from pydase.utils.logging import configure_root_logger_with_pydase_formatter -def test_log_error(caplog: LogCaptureFixture): +def test_log_error(caplog: pytest.LogCaptureFixture) -> None: logger = logging.getLogger("pydase") logger.setLevel(logging.ERROR) @@ -20,7 +21,7 @@ def test_log_error(caplog: LogCaptureFixture): assert any(record.levelname == "ERROR" for record in caplog.records) -def test_log_warning(caplog: LogCaptureFixture): +def test_log_warning(caplog: pytest.LogCaptureFixture) -> None: logger = logging.getLogger("pydase") logger.setLevel(logging.WARNING) @@ -37,7 +38,7 @@ def test_log_warning(caplog: LogCaptureFixture): assert any(record.levelname == "ERROR" for record in caplog.records) -def test_log_debug(caplog: LogCaptureFixture): +def test_log_debug(caplog: pytest.LogCaptureFixture) -> None: logger = logging.getLogger("pydase") logger.setLevel(logging.DEBUG) @@ -53,7 +54,7 @@ def test_log_debug(caplog: LogCaptureFixture): assert "This is an error message" in caplog.text -def test_log_info(caplog: LogCaptureFixture): +def test_log_info(caplog: pytest.LogCaptureFixture) -> None: logger = logging.getLogger("pydase") logger.setLevel(logging.INFO) @@ -67,3 +68,21 @@ def test_log_info(caplog: LogCaptureFixture): assert "This is an info message" in caplog.text assert "This is a warning message" in caplog.text assert "This is an error message" in caplog.text + + +def test_before_configuring_root_logger(caplog: pytest.LogCaptureFixture) -> None: + logger = logging.getLogger(__name__) + logger.info("Hello world") + + assert "Hello world" not in caplog.text + + +def test_configure_root_logger(caplog: pytest.LogCaptureFixture) -> None: + configure_root_logger_with_pydase_formatter() + logger = logging.getLogger(__name__) + logger.info("Hello world") + + assert ( + "INFO tests.utils.test_logging:test_logging.py:83 Hello world" + in caplog.text + )