Visitar URL original
Reject negative log_auto_indent values (#14586) · pytest-dev/pytest@771ab77 · GitHub
Skip to content

Commit 771ab77

Browse files
authored
Reject negative log_auto_indent values (#14586)
* Reject negative log_auto_indent values * Changelog added
1 parent d575dba commit 771ab77

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎changelog/14586.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Negative values passed to ``log_auto_indent`` now correctly fall back to no indentation, matching the documented behavior.

‎src/_pytest/logging.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ def _get_auto_indent(auto_indent_option: int | str | bool | None) -> int:
186186
case True:
187187
return -1
188188
case int():
189-
return auto_indent_option
189+
return max(auto_indent_option, 0)
190190
case str():
191191
try:
192-
return int(auto_indent_option)
192+
return max(int(auto_indent_option), 0)
193193
except ValueError:
194194
pass
195195
try:

‎testing/logging/test_formatter.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ def test_multiline_message() -> None:
149149
"dummypath 10 INFO Test Message line1\n line2"
150150
)
151151

152+
record.auto_indent = "-5"
153+
output = ai_off_style.format(record)
154+
assert output == (
155+
"dummypath 10 INFO Test Message line1\nline2"
156+
)
157+
158+
record.auto_indent = -5
159+
output = ai_off_style.format(record)
160+
assert output == (
161+
"dummypath 10 INFO Test Message line1\nline2"
162+
)
163+
152164

153165
def test_colored_short_level() -> None:
154166
logfmt = "%(levelname).1s %(message)s"

0 commit comments

Comments
 (0)