#4222·rich

[BUG] Console tests fail when COLUMNS or LINES is exported in the shell

Author: meagoodboyCreated Sep 16, 2026Updated Sep 16, 2026
  • I've checked docs and closed issues for possible solutions.
  • I can't find my issue in the FAQ.

Describe the bug

Running the test suite in a shell that exports COLUMNS (as CI systems and some terminal multiplexers do) makes 6 tests in tests/test_console.py fail, because the environment takes precedence over the mocked terminal size:

COLUMNS=200 LINES=50 python -m pytest tests/test_console.py -p no:randomly
FAILED tests/test_console.py::test_size_can_fall_back_to_std_descriptors[False-ValueError-ValueError-ValueError-ValueError-expected_size5]
  assert (200, 50) == (80, 25)
6 failed, 94 passed

Without the variables exported the same file passes 100/100. I checked this in a controlled comparison (32 runs with the variables exported vs 32 without, with hash seed, timezone and locale also varied as controls): 0/32 pass exported, 32/32 pass clean, and none of the control factors move the result.

The library behavior is intentional (Console.__init__ reads COLUMNS and LINES from self._environ, rich/console.py around line 685). The tests just never isolate themselves from the inherited environment, while other test files already do: tests/test_tree.py and tests/test_logging.py construct their consoles with _environ={} for exactly this reason.

Proposed fix

Pass _environ={} to the Console instances in the affected tests/test_console.py tests (or scrub COLUMNS/LINES with an autouse monkeypatch fixture for that file). Happy to send a PR if that direction works for you.

Platform

Reproduced on macOS (arm64), Python 3.13, pytest 9.1.1, at master 9d8f9a3; the mechanism only depends on the inherited environment, so it should not be platform-specific.

Investigated with the help of Claude (Anthropic's Claude Code).