MCPcopy
hub / github.com/pytest-dev/pytest / PercentStyleMultiline

Class PercentStyleMultiline

src/_pytest/logging.py:140–223  ·  view source on GitHub ↗

A logging style with special support for multiline messages. If the message of a record consists of multiple lines, this style formats the message as if each line were logged separately.

Source from the content-addressed store, hash-verified

138
139
140class PercentStyleMultiline(logging.PercentStyle):
141 """A logging style with special support for multiline messages.
142
143 If the message of a record consists of multiple lines, this style
144 formats the message as if each line were logged separately.
145 """
146
147 def __init__(self, fmt: str, auto_indent: int | str | bool | None) -> None:
148 super().__init__(fmt)
149 self._auto_indent = self._get_auto_indent(auto_indent)
150
151 @staticmethod
152 def _get_auto_indent(auto_indent_option: int | str | bool | None) -> int:
153 """Determine the current auto indentation setting.
154
155 Specify auto indent behavior (on/off/fixed) by passing in
156 extra={"auto_indent": [value]} to the call to logging.log() or
157 using a --log-auto-indent [value] command line or the
158 log_auto_indent [value] config option.
159
160 Default behavior is auto-indent off.
161
162 Using the string "True" or "on" or the boolean True as the value
163 turns auto indent on, using the string "False" or "off" or the
164 boolean False or the int 0 turns it off, and specifying a
165 positive integer fixes the indentation position to the value
166 specified.
167
168 Any other values for the option are invalid, and will silently be
169 converted to the default.
170
171 :param None|bool|int|str auto_indent_option:
172 User specified option for indentation from command line, config
173 or extra kwarg. Accepts int, bool or str. str option accepts the
174 same range of values as boolean config options, as well as
175 positive integers represented in str form.
176
177 :returns:
178 Indentation value, which can be
179 -1 (automatically determine indentation) or
180 0 (auto-indent turned off) or
181 >0 (explicitly set indentation position).
182 """
183 match auto_indent_option:
184 case None | False:
185 return 0
186 case True:
187 return -1
188 case int():
189 return auto_indent_option
190 case str():
191 try:
192 return int(auto_indent_option)
193 except ValueError:
194 pass
195 try:
196 if _strtobool(auto_indent_option):
197 return -1

Callers 2

test_multiline_messageFunction · 0.90
_create_formatterMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_multiline_messageFunction · 0.72