Skip to content

[refactor] Introduce a TruncationBudget for assertion truncation#14652

Open
Pierre-Sassoulas wants to merge 1 commit into
pytest-dev:mainfrom
Pierre-Sassoulas:truncation-budget-refactor
Open

[refactor] Introduce a TruncationBudget for assertion truncation#14652
Pierre-Sassoulas wants to merge 1 commit into
pytest-dev:mainfrom
Pierre-Sassoulas:truncation-budget-refactor

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Proposal of refactor prior to #14523 where a lot of truncation budget will be passed around in assertion generator.

Bundle the (max_lines, max_chars) pair that the truncation machinery passes around into a small frozen, keyword-only TruncationBudget. _get_truncation_parameters now returns (should_truncate, budget) and _truncate_explanation takes the budget directly. Keyword-only construction means the two limits can never be silently swapped at a call site.

The budget carries the truncation_limit_lines / truncation_limit_chars ini values verbatim — positive bounds the dimension, 0 leaves it unbounded — so there is no extra sentinel translation. Pure refactor: truncation behaviour, footer wording and hidden-line count are unchanged.

Bundle the (max_lines, max_chars) pair that the truncation machinery
passes around into a small frozen, keyword-only TruncationBudget.
_get_truncation_parameters now returns (should_truncate, budget) and
_truncate_explanation takes the budget directly. Keyword-only
construction means the two limits can never be silently swapped at a
call site.

The budget carries the truncation_limit_lines / truncation_limit_chars
ini values verbatim — positive bounds the dimension, 0 leaves it
unbounded — so there is no extra sentinel translation. Pure refactor:
truncation behaviour, footer wording and hidden-line count are
unchanged.
@Pierre-Sassoulas Pierre-Sassoulas added the skip news used on prs to opt out of the changelog requirement label Jun 25, 2026
@Pierre-Sassoulas

Copy link
Copy Markdown
Member Author

@bluetech what do you think ?

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

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant