Skip to content

✨ feat(cli): add --no-capture flag for interactive programs#3777

Merged
gaborbernat merged 3 commits intotox-dev:mainfrom
gaborbernat:fix/windows-repl-3635
Feb 19, 2026
Merged

✨ feat(cli): add --no-capture flag for interactive programs#3777
gaborbernat merged 3 commits intotox-dev:mainfrom
gaborbernat:fix/windows-repl-3635

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented Feb 19, 2026

Interactive programs like Python REPL, debuggers, and TUI applications need direct terminal access to work correctly. They query console dimensions, set raw mode for keystroke input, and send VT100 escape sequences for cursor control. 🐛 Tox normally pipes stdout/stderr to capture output for logging and result reporting, but this breaks terminal APIs that require real console handles instead of pipe handles. Python 3.13+ REPL crashes on Windows with WinError 123 when _pyrepl/windows_console.py tries to call Win32 APIs that only work on console buffers, and similar failures occur on other platforms when programs try to query terminal properties.

The new --no-capture (-i) flag disables output capture and makes subprocesses inherit parent console handles directly. ✨ This is opt-in because it's mutually exclusive with --result-json where output must be captured, and parallel mode where output from multiple environments would interleave. The implementation validates incompatible flag combinations early with clear error messages. Additionally, tox exec now always runs with no_capture enabled since it's designed for one-off interactive commands, and the flag is hidden from its help output to avoid confusion.

The flag works on all platforms since terminal APIs universally require console handles, not just on Windows. Documentation has been added to both the how-to guide for practical usage and the explanation section to clarify why interactive terminal programs need special handling.

Interactive programs like Python REPL need direct terminal access to query
console dimensions and handle user input. Tox normally pipes stdout/stderr
for output capture, giving subprocesses pipe handles instead of console
handles. This causes Python 3.13+ REPL to crash on Windows with WinError 123
when _pyrepl/windows_console.py calls Win32 APIs that require real console
buffers.

Add --no-capture (-i) CLI flag that makes subprocesses inherit parent console
handles instead of using pipes. This is opt-in because it's mutually exclusive
with result logging (--result-json) and parallel mode where output capture is
essential. The flag is platform-independent since terminal APIs need console
handles on all platforms, not just Windows.

Validates incompatible flag combinations early with clear error messages.
@gaborbernat gaborbernat force-pushed the fix/windows-repl-3635 branch from a7d0944 to 8d017eb Compare February 19, 2026 17:55
@gaborbernat gaborbernat enabled auto-merge (squash) February 19, 2026 17:56
Test failures occurred because MagicMock objects return new MagicMock instances
for undefined attributes, which evaluate to True. When tests accessed
`env.options.no_capture` on mocked environments, this truthy mock caused
subprocesses to inherit console handles instead of capturing output, breaking
assertions that expected captured stdout/stderr.

Explicitly set `no_capture = False` on all mock tox environments to ensure
output capture behaves correctly in tests. Also updated test expectations to
include the no_capture field now present in parsed options for commands that
support environment arguments.
@gaborbernat gaborbernat disabled auto-merge February 19, 2026 19:54
@gaborbernat gaborbernat enabled auto-merge (squash) February 19, 2026 19:54
@gaborbernat gaborbernat merged commit cf64528 into tox-dev:main Feb 19, 2026
28 checks passed
@gaborbernat gaborbernat deleted the fix/windows-repl-3635 branch February 19, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant