From d279429c99184c98499eaeebd6fdccc0e854da41 Mon Sep 17 00:00:00 2001 From: Dresden Date: Tue, 28 Jul 2026 01:33:13 -0700 Subject: [PATCH] Accept integer TOML truncation limits --- changelog/14675.improvement.rst | 1 + src/_pytest/assertion/__init__.py | 2 ++ testing/test_assertion.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog/14675.improvement.rst diff --git a/changelog/14675.improvement.rst b/changelog/14675.improvement.rst new file mode 100644 index 00000000000..fb4c4f32580 --- /dev/null +++ b/changelog/14675.improvement.rst @@ -0,0 +1 @@ +Native TOML integer values are now accepted for the :confval:`truncation_limit_lines` and :confval:`truncation_limit_chars` configuration options. diff --git a/src/_pytest/assertion/__init__.py b/src/_pytest/assertion/__init__.py index ad2454ab820..15eb5fd34ec 100644 --- a/src/_pytest/assertion/__init__.py +++ b/src/_pytest/assertion/__init__.py @@ -51,11 +51,13 @@ def pytest_addoption(parser: Parser) -> None: parser.addini( "truncation_limit_lines", + type=int | str, default=None, help="Set threshold of LINES after which truncation will take effect", ) parser.addini( "truncation_limit_chars", + type=int | str, default=None, help=("Set threshold of CHARS after which truncation will take effect"), ) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 609c4b1a62f..afa7f7d200b 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1796,10 +1796,12 @@ def test_many_lines(): (1000, 0, 0), ), ) - def test_truncation_with_ini( + @pytest.mark.parametrize("config_format", ["ini", "toml"]) + def test_truncation_with_config( self, monkeypatch, pytester: Pytester, + config_format: str, truncation_lines: int | None, truncation_chars: int | None, expected_lines_hidden: int, @@ -1820,12 +1822,15 @@ def test(): monkeypatch.delenv("CI", raising=False) - ini = "[pytest]\n" + ini = "[pytest]\n" if config_format == "ini" else "[tool.pytest]\n" if truncation_lines is not None: ini += f"truncation_limit_lines = {truncation_lines}\n" if truncation_chars is not None: ini += f"truncation_limit_chars = {truncation_chars}\n" - pytester.makeini(ini) + if config_format == "ini": + pytester.makeini(ini) + else: + pytester.makepyprojecttoml(ini) result = pytester.runpytest()