MCPcopy Create free account
hub / github.com/pytest-dev/pytest / PercentStyleMultiline

Class PercentStyleMultiline

src/_pytest/logging.py:110–197  ·  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

108
109
110class PercentStyleMultiline(logging.PercentStyle):
111 """A logging style with special support for multiline messages.
112
113 If the message of a record consists of multiple lines, this style
114 formats the message as if each line were logged separately.
115 """
116
117 def __init__(self, fmt: str, auto_indent: Union[int, str, bool, None]) -> None:
118 super().__init__(fmt)
119 self._auto_indent = self._get_auto_indent(auto_indent)
120
121 @staticmethod
122 def _get_auto_indent(auto_indent_option: Union[int, str, bool, None]) -> int:
123 """Determine the current auto indentation setting.
124
125 Specify auto indent behavior (on/off/fixed) by passing in
126 extra={"auto_indent": [value]} to the call to logging.log() or
127 using a --log-auto-indent [value] command line or the
128 log_auto_indent [value] config option.
129
130 Default behavior is auto-indent off.
131
132 Using the string "True" or "on" or the boolean True as the value
133 turns auto indent on, using the string "False" or "off" or the
134 boolean False or the int 0 turns it off, and specifying a
135 positive integer fixes the indentation position to the value
136 specified.
137
138 Any other values for the option are invalid, and will silently be
139 converted to the default.
140
141 :param None|bool|int|str auto_indent_option:
142 User specified option for indentation from command line, config
143 or extra kwarg. Accepts int, bool or str. str option accepts the
144 same range of values as boolean config options, as well as
145 positive integers represented in str form.
146
147 :returns:
148 Indentation value, which can be
149 -1 (automatically determine indentation) or
150 0 (auto-indent turned off) or
151 >0 (explicitly set indentation position).
152 """
153
154 if auto_indent_option is None:
155 return 0
156 elif isinstance(auto_indent_option, bool):
157 if auto_indent_option:
158 return -1
159 else:
160 return 0
161 elif isinstance(auto_indent_option, int):
162 return int(auto_indent_option)
163 elif isinstance(auto_indent_option, str):
164 try:
165 return int(auto_indent_option)
166 except ValueError:
167 pass

Callers 2

test_multiline_messageFunction · 0.90
_create_formatterMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_multiline_messageFunction · 0.72