Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14586.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Negative values passed to ``log_auto_indent`` now correctly fall back to no indentation, matching the documented behavior.
4 changes: 2 additions & 2 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def _get_auto_indent(auto_indent_option: int | str | bool | None) -> int:
case True:
return -1
case int():
return auto_indent_option
return max(auto_indent_option, 0)
case str():
try:
return int(auto_indent_option)
return max(int(auto_indent_option), 0)
except ValueError:
pass
try:
Expand Down
12 changes: 12 additions & 0 deletions testing/logging/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ def test_multiline_message() -> None:
"dummypath 10 INFO Test Message line1\n line2"
)

record.auto_indent = "-5"
output = ai_off_style.format(record)
assert output == (
"dummypath 10 INFO Test Message line1\nline2"
)

record.auto_indent = -5
output = ai_off_style.format(record)
assert output == (
"dummypath 10 INFO Test Message line1\nline2"
)


def test_colored_short_level() -> None:
logfmt = "%(levelname).1s %(message)s"
Expand Down
Loading