Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions tests/hermes_cli/test_update_yes_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ def test_no_yes_flag_still_prompts_in_tty(

args = SimpleNamespace(yes=False)

with patch("builtins.input", return_value="n") as mock_input, patch(
"hermes_cli.main.sys"
) as mock_sys:
mock_sys.stdin.isatty.return_value = True
mock_sys.stdout.isatty.return_value = True
# Patch ``sys.stdin.isatty`` and ``sys.stdout.isatty`` directly on the
# real ``sys`` module instead of replacing ``hermes_cli.main.sys`` with
# a MagicMock. The MagicMock approach was flaky under ``pytest-xdist``
# — a sibling test that imported ``hermes_cli.main`` first could leave
# a different ``sys`` reference resolved inside the function and the
# mock would never be consulted, with CI then taking the
# "Non-interactive session" branch instead of prompting.
import sys as _sys

with patch("builtins.input", return_value="n") as mock_input, patch.object(
_sys.stdin, "isatty", return_value=True
), patch.object(_sys.stdout, "isatty", return_value=True):
cmd_update(args)
# The user was actually prompted.
assert mock_input.called
Expand Down Expand Up @@ -156,7 +163,16 @@ def test_yes_restores_stash_without_prompting(

args = SimpleNamespace(yes=True)

cmd_update(args)
# Force a TTY-shaped session so the autostash-restore branch is
# reachable in CI workers regardless of inherited stdio (matches the
# isatty patching strategy in ``test_no_yes_flag_still_prompts_in_tty``
# — ``patch.object`` on the real streams is robust under xdist).
import sys as _sys

with patch.object(_sys.stdin, "isatty", return_value=True), patch.object(
_sys.stdout, "isatty", return_value=True
):
cmd_update(args)

# _restore_stashed_changes was called, and called with prompt_user=False
# every time (so the user never sees "Restore local changes now?").
Expand Down
Loading