feat: read output width from the environment when there is no tty - #65
Merged
Merged
Conversation
The reporter console is built with force_terminal=True so colors survive being piped, but that also makes rich skip its own COLUMNS handling. With no tty to measure, the width was pinned to 200 and the session header to 120, so neither could be adjusted for a CI log viewer. Read COLUMNS, or PYTEST_MODERN_WIDTH to set the width without affecting other tools, and keep 200 as the fallback. The header panel now tracks the console width instead of overflowing a narrower one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The reporter console is built with
force_terminal=Trueso colors survive beingpiped. That flag also makes rich skip its own
COLUMNShandling, and with no ttyto measure the width was pinned:
So in a CI log there was no way to adjust the width — setting
COLUMNShad noeffect, because the explicit
width=argument overrides it.Change
Add
console_width(), which resolves in the order: no width on a tty (richmeasures it) →
COLUMNS→PYTEST_MODERN_WIDTH→ 200 as the fallback.Non-numeric and non-positive values are ignored rather than raising.
PYTEST_MODERN_WIDTHis there so the width can be set withoutCOLUMNSaffecting every other tool in the same shell.
The session header now uses
min(120, self.console.width)so it tracks anarrower console instead of overflowing it.
Verification
console_width()across inputs:COLUMNS100160240abc0-5Test suite compared against
mainwith reruns disabled to remove thenondeterminism — identical on both: 12 passed, 4 failed, 2 timeout. (Those
failures are the intentional demo fixtures in
tests/.)ruff checkandruff formatpass.Note
The hunk at
terminal.py:277reformats a pre-existing longlambdaline and isunrelated to this change —
ruff formatinsists on it, so reverting it wouldfail pre-commit.ci.