Skip to content

Commit

Permalink
Add test case for Uvicorn log format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
br3ndonland committed Jul 31, 2022
1 parent 8c474b6 commit 087efda
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/test_logging_conf.py
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 087efda

Please sign in to comment.