From e0410d75921d9a93a83b133661b7a0004ae2c599 Mon Sep 17 00:00:00 2001 From: syncrain Date: Sat, 13 Jun 2026 19:13:37 +0530 Subject: [PATCH 1/2] Reject negative log_auto_indent values --- src/_pytest/logging.py | 4 ++-- testing/logging/test_formatter.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 3204d43ee01..982e12cd8c2 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -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: diff --git a/testing/logging/test_formatter.py b/testing/logging/test_formatter.py index cfe3bee68c4..28a31e7d105 100644 --- a/testing/logging/test_formatter.py +++ b/testing/logging/test_formatter.py @@ -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" From 60835b4993da146c43766ac9d2c8704cb627cea2 Mon Sep 17 00:00:00 2001 From: syncrain Date: Sat, 13 Jun 2026 19:24:01 +0530 Subject: [PATCH 2/2] Changelog added --- changelog/14586.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/14586.bugfix.rst diff --git a/changelog/14586.bugfix.rst b/changelog/14586.bugfix.rst new file mode 100644 index 00000000000..54b72253df9 --- /dev/null +++ b/changelog/14586.bugfix.rst @@ -0,0 +1 @@ +Negative values passed to ``log_auto_indent`` now correctly fall back to no indentation, matching the documented behavior.