Skip to content

Allow int for truncation_limit_lines and truncation_limit_chars in TOML#14692

Open
Pierre-Sassoulas wants to merge 2 commits into
pytest-dev:mainfrom
Pierre-Sassoulas:fix-truncation-limit-int-14675
Open

Allow int for truncation_limit_lines and truncation_limit_chars in TOML#14692
Pierre-Sassoulas wants to merge 2 commits into
pytest-dev:mainfrom
Pierre-Sassoulas:fix-truncation-limit-int-14675

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

The truncation_limit_lines and truncation_limit_chars ini options were registered without a type, defaulting to 'string'. In native TOML config ([tool.pytest]), integer values then raised a TypeError instead of being accepted, despite being numeric limits.

Register both options with type='int' so TOML integer values are accepted (INI string values keep working via the existing int coercion).

Basically #14689 but without unwanted AI to human conversation.

Fixes #14675

The truncation_limit_lines and truncation_limit_chars ini options were
registered without a type, defaulting to 'string'. In native TOML config
([tool.pytest]), integer values then raised a TypeError instead of being
accepted, despite being numeric limits.

Register both options with type='int' so TOML integer values are accepted
(INI string values keep working via the existing int coercion).

Fixes pytest-dev#14675
With truncation_limit_lines/chars registered as type='int', getini returns
int | None directly. TruncationBudget.from_config now owns reading those
ini options and resolving None (option unset) to the DEFAULT_MAX_* limit,
which lives next to the class.

The _get_truncation_parameters helper is inlined into truncate_if_required,
which short-circuits on verbosity/CI before reading the options at all.
String values from INI files and -o overrides are still coerced centrally
by the config layer. None means 'use default'; 0 means 'unbounded'.

@bluetech bluetech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just change to int, as that would be a breaking change. We need to allow both, unfortunately.

I will write in the issue how I think we can do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

truncation_limit_lines and truncation_limit_chars should accept integer values in .toml configs

2 participants