Skip to content

Commit

Permalink
Add test for disable_existing_loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Dec 9, 2024
1 parent 63ac05a commit cb5199b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_utils_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from fastapi_cli.utils.cli import CustomFormatter, get_uvicorn_log_config
from pytest import LogCaptureFixture


def test_get_uvicorn_config_uses_custom_formatter() -> None:
Expand Down Expand Up @@ -33,3 +34,22 @@ def test_custom_formatter() -> None:
assert "127.0.0.1" in formatted
assert "GET / HTTP/1.1" in formatted
assert "200" in formatted


def test_log_config_does_not_disable_existing_loggers(
caplog: LogCaptureFixture,
) -> None:
logger1 = logging.getLogger(__name__)
logger1.setLevel(logging.INFO)
logger1.info("Message before configuration")

logging.config.dictConfig(get_uvicorn_log_config())

logger2 = logging.getLogger(__name__)

logger1.info("Message after configuration from logger1") # Should not appear
logger2.info("Message from logger2")

assert "Message before configuration" in caplog.text
assert "Message after configuration from logger1" in caplog.text
assert "Message from logger2" in caplog.text

0 comments on commit cb5199b

Please sign in to comment.