Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not set COLUMNS or LINES if already set by user #2580

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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