Skip to content

Commit c0bea7f

Browse files
committed
test(conftest): 🔧 force wide terminal for Rich-based CLI assertions
1 parent f9b43ae commit c0bea7f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@
4949
SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER = check_local_data_entity_existence.identifier
5050

5151

52+
@pytest.fixture(scope="session", autouse=True)
53+
def _session_wide_terminal():
54+
"""
55+
Force Rich (and other ``os.get_terminal_size`` consumers) to render with
56+
a wide terminal. ``click.testing.CliRunner`` captures stdout into a
57+
StringIO, so Rich falls back to its 80-column default and truncates
58+
table cells / wraps panel rows — breaking ``"substring" in result.output``
59+
assertions in a non-deterministic way. Setting ``COLUMNS`` early keeps
60+
the rendered output predictable across machines and CI.
61+
"""
62+
previous_columns = os.environ.get("COLUMNS")
63+
previous_lines = os.environ.get("LINES")
64+
os.environ["COLUMNS"] = "200"
65+
os.environ["LINES"] = "50"
66+
try:
67+
yield
68+
finally:
69+
for name, prev in (("COLUMNS", previous_columns), ("LINES", previous_lines)):
70+
if prev is None:
71+
os.environ.pop(name, None)
72+
else:
73+
os.environ[name] = prev
74+
75+
5276
@pytest.fixture(scope="session", autouse=True)
5377
def _session_isolated_xdg(tmp_path_factory):
5478
"""

0 commit comments

Comments
 (0)