From 087efda8536e5df343d3d550a3b42d32513e54cf Mon Sep 17 00:00:00 2001 From: Brendon Smith Date: Sat, 30 Jul 2022 20:04:58 -0400 Subject: [PATCH] Add test case for Uvicorn log format This commit will add a pytest parameter that verifies log message output after configuring logging with the Uvicorn log format. This parameter is important for testing not only for the log message format, but also the use of the `uvicorn.logging.DefaultFormatter` class and its module. The module has been renamed from `uvicorn.logging` to `uvicorn._logging`, then reverted back to `uvicorn.logging`. The test will help ensure that the Uvicorn module path (`uvicorn.logging.DefaultFormatter`) is correct. encode/uvicorn#1543 --- tests/test_logging_conf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_logging_conf.py b/tests/test_logging_conf.py index 67bc86d..b70a5aa 100644 --- a/tests/test_logging_conf.py +++ b/tests/test_logging_conf.py @@ -160,7 +160,8 @@ def test_logging_output_default(self, capfd: pytest.CaptureFixture) -> None: assert "Hello, World!" in captured.out @pytest.mark.parametrize( - "log_format,log_level_output", (("gunicorn", "[DEBUG]"), ("verbose", "DEBUG")) + "log_format,log_level_output", + (("gunicorn", "[DEBUG]"), ("uvicorn", "DEBUG: "), ("verbose", "DEBUG ")), ) def test_logging_output_custom_format( self, @@ -172,7 +173,7 @@ def test_logging_output_custom_format( ) -> None: """Test logger output with custom format.""" logging_conf_file = f"{logging_conf_tmp_file_path}/tmp_log.py" - monkeypatch.setenv("LOG_FORMAT", "gunicorn") + monkeypatch.setenv("LOG_FORMAT", log_format) monkeypatch.setenv("LOG_LEVEL", "debug") logger = logging_conf.logging.getLogger() logging_conf.configure_logging(logging_conf=logging_conf_file)