Skip to content

Commit cb5199b

Browse files
committed
Add test for disable_existing_loggers
1 parent 63ac05a commit cb5199b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_utils_cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from fastapi_cli.utils.cli import CustomFormatter, get_uvicorn_log_config
4+
from pytest import LogCaptureFixture
45

56

67
def test_get_uvicorn_config_uses_custom_formatter() -> None:
@@ -33,3 +34,22 @@ def test_custom_formatter() -> None:
3334
assert "127.0.0.1" in formatted
3435
assert "GET / HTTP/1.1" in formatted
3536
assert "200" in formatted
37+
38+
39+
def test_log_config_does_not_disable_existing_loggers(
40+
caplog: LogCaptureFixture,
41+
) -> None:
42+
logger1 = logging.getLogger(__name__)
43+
logger1.setLevel(logging.INFO)
44+
logger1.info("Message before configuration")
45+
46+
logging.config.dictConfig(get_uvicorn_log_config())
47+
48+
logger2 = logging.getLogger(__name__)
49+
50+
logger1.info("Message after configuration from logger1") # Should not appear
51+
logger2.info("Message from logger2")
52+
53+
assert "Message before configuration" in caplog.text
54+
assert "Message after configuration from logger1" in caplog.text
55+
assert "Message from logger2" in caplog.text

0 commit comments

Comments
 (0)