diff options
author | Thomas Hisch <t.hisch@gmail.com> | 2019-05-24 04:32:22 +0200 |
---|---|---|
committer | Thomas Hisch <t.hisch@gmail.com> | 2019-05-29 23:21:14 +0200 |
commit | ea3ebec117b6f06b0a584f39ecaa8e75976a6e37 (patch) | |
tree | 96aa6593f82e2079dedd49401e36b8d281a24261 /testing/logging | |
parent | 84569ca4daacb273f21b0bd9f52885fae2bccaf7 (diff) | |
download | pytest-ea3ebec117b6f06b0a584f39ecaa8e75976a6e37.tar.gz |
logging: Improve formatting of multiline message
Diffstat (limited to 'testing/logging')
-rw-r--r-- | testing/logging/test_formatter.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/testing/logging/test_formatter.py b/testing/logging/test_formatter.py index 1610da845..c851c34d7 100644 --- a/testing/logging/test_formatter.py +++ b/testing/logging/test_formatter.py @@ -2,7 +2,9 @@ import logging import py.io +import six +import pytest from _pytest.logging import ColoredLevelFormatter @@ -35,3 +37,31 @@ def test_coloredlogformatter(): formatter = ColoredLevelFormatter(tw, logfmt) output = formatter.format(record) assert output == ("dummypath 10 INFO Test Message") + + +@pytest.mark.skipif( + six.PY2, reason="Formatter classes don't support format styles in PY2" +) +def test_multiline_message(): + from _pytest.logging import PercentStyleMultiline + + logfmt = "%(filename)-25s %(lineno)4d %(levelname)-8s %(message)s" + + record = logging.LogRecord( + name="dummy", + level=logging.INFO, + pathname="dummypath", + lineno=10, + msg="Test Message line1\nline2", + args=(), + exc_info=False, + ) + # this is called by logging.Formatter.format + record.message = record.getMessage() + + style = PercentStyleMultiline(logfmt) + output = style.format(record) + assert output == ( + "dummypath 10 INFO Test Message line1\n" + " line2" + ) |