Skip to content

Commit

Permalink
Do not set COLUMNS or LINES if already set by user (#2580)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Dec 3, 2022
1 parent 188ba4a commit 3bae5d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/2575.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Do not set ``COLUMNS`` or ``LINES`` environment to the current TTY size if already set by the user -
by :user:`gaborbernat`.
6 changes: 3 additions & 3 deletions src/tox/execute/local_sub_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def __enter__(self) -> ExecuteStatus:
# adjust sub-process terminal size
columns, lines = shutil.get_terminal_size(fallback=(-1, -1))
if columns != -1: # pragma: no branch
self.request.env["COLUMNS"] = str(columns)
if columns != -1: # pragma: no branch
self.request.env["LINES"] = str(lines)
self.request.env.setdefault("COLUMNS", str(columns))
if lines != -1: # pragma: no branch
self.request.env.setdefault("LINES", str(lines))

stdout, stderr = self.get_stream_file_no("stdout"), self.get_stream_file_no("stderr")
try:
Expand Down
18 changes: 18 additions & 0 deletions tests/execute/local_subprocess/test_local_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,21 @@ def _create_shebang_test(tmp_path: Path, env: dict[str, str]) -> tuple[str, Path
writer = create_autospec(SyncWrite)
instance = LocalSubProcessExecuteInstance(request, create_autospec(ExecuteOptions), writer, writer)
return exe, script, instance


@pytest.mark.parametrize("key", ["COLUMNS", "ROWS"])
def test_local_execute_does_not_overwrite(key: str, mocker: MockerFixture) -> None:
mocker.patch("shutil.get_terminal_size", return_value=(101, 102))
env = dict(os.environ)
env[key] = key
executor = LocalSubProcessExecutor(colored=False)
cmd = [sys.executable, "-c", f"import os; print(os.environ['{key}'], end='')"]
request = ExecuteRequest(cmd=cmd, stdin=StdinSource.API, cwd=Path.cwd(), env=env, run_id="")
out_err = FakeOutErr()
with executor.call(request, show=False, out_err=out_err.out_err, env=MagicMock()) as status:
while status.exit_code is None: # pragma: no branch
status.wait()
outcome = status.outcome

assert outcome is not None
assert outcome.out == key

0 comments on commit 3bae5d9

Please sign in to comment.