Skip to content

Commit 4848f14

Browse files
committed
Clean up test style to match project conventions
Shorten verbose docstrings in unit and integration tests to single-line summaries (or remove entirely where function names are self-explanatory), and shorten overly long integration test function names. This aligns the new TTY-related tests with the existing test style in the same files. Signed-off-by: xz-dev <xiangzhedev@gmail.com>
1 parent 5aaddba commit 4848f14

File tree

4 files changed

+8
-58
lines changed

4 files changed

+8
-58
lines changed

src/ansible_runner/config/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ def _handle_ansible_cmd_options_bind_mounts(self, args_list: list[str], cmdline_
487487

488488
self._update_volume_mount_paths(args_list, optional_arg_value)
489489

490-
491490
def _should_allocate_tty(self) -> bool:
492491
if self.runner_mode == 'pexpect':
493492
return True

test/integration/containerized/test_container_management.py

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,8 @@ def test_registry_auth_file_cleanup(tmp_path, cli, runtime):
181181

182182

183183
@pytest.mark.test_all_runtimes
184-
def test_containerized_run_command_no_tty_when_input_fd_is_not_a_terminal(tmp_path, runtime, container_image):
185-
"""Verify --tty is not passed to the container when input_fd is not a real TTY.
186-
187-
Regression test for ansible-runner PR#1306 (partial fix for
188-
ansible-navigator#1607). When ansible-navigator runs in a CI/CD
189-
pipeline or cron job, sys.stdin is not a terminal, yet it is still
190-
forwarded to ansible-runner as input_fd. Before the fix, any truthy
191-
input_fd caused --tty to be added, making the container allocate a
192-
pseudo-terminal and polluting output with ANSI escape sequences.
193-
194-
This test uses a regular file as input_fd (isatty() == False) to
195-
simulate the non-TTY scenario and asserts that the containerized
196-
``ansible-config init`` output is clean.
197-
198-
NOTE: the original issue also manifests when stdin *is* a TTY but
199-
stdout is redirected (``> ansible.cfg``). That scenario is not
200-
covered here because it requires a different fix (e.g. checking
201-
output_fd.isatty() or handling it on the navigator side).
202-
"""
184+
def test_containerized_no_tty_when_stdin_not_terminal(tmp_path, runtime, container_image):
185+
"""Regression for ansible-navigator#1607: no --tty when input_fd is not a real TTY."""
203186
input_path = tmp_path / 'stdin.txt'
204187
output_path = tmp_path / 'ansible.cfg'
205188
error_path = tmp_path / 'stderr.txt'
@@ -230,23 +213,8 @@ def test_containerized_run_command_no_tty_when_input_fd_is_not_a_terminal(tmp_pa
230213

231214

232215
@pytest.mark.test_all_runtimes
233-
def test_containerized_run_command_no_ansi_when_stdout_redirected_but_stdin_is_tty(
234-
tmp_path, runtime, container_image,
235-
):
236-
"""Reproduce the exact ansible-navigator#1607 scenario.
237-
238-
The user runs ``ansible-navigator config init -m stdout > ansible.cfg``
239-
from a real terminal. ansible-navigator forwards sys.stdin (a TTY) as
240-
input_fd and sys.stdout (redirected to a file, not a TTY) as output_fd.
241-
242-
The container must not receive --tty in this situation; otherwise
243-
``ansible-config init`` detects a pseudo-terminal inside the container
244-
and emits ANSI escape sequences / launches a pager.
245-
246-
This test uses pty.openpty() to obtain an input_fd where isatty()
247-
is True, while output_fd is a regular file (isatty() == False),
248-
matching the real-world trigger exactly.
249-
"""
216+
def test_containerized_no_tty_when_stdout_redirected(tmp_path, runtime, container_image):
217+
"""Regression for ansible-navigator#1607: no --tty when stdin is TTY but stdout is redirected."""
250218
output_path = tmp_path / 'ansible.cfg'
251219
error_path = tmp_path / 'stderr.txt'
252220

test/unit/config/test__base.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ def test_containerization_unsafe_write_setting(tmp_path, runtime, mocker):
372372

373373

374374
def test_should_allocate_tty_pexpect_mode(tmp_path, mocker):
375-
"""pexpect mode always allocates a TTY even when input_fd is not a terminal."""
376375
rc = BaseConfig(private_data_dir=str(tmp_path))
377376
rc.runner_mode = 'pexpect'
378377
rc.input_fd = mocker.Mock()
@@ -381,14 +380,12 @@ def test_should_allocate_tty_pexpect_mode(tmp_path, mocker):
381380

382381

383382
def test_should_allocate_tty_subprocess_no_input_fd(tmp_path):
384-
"""subprocess mode without input_fd does not allocate TTY (AWX scenario)."""
385383
rc = BaseConfig(private_data_dir=str(tmp_path))
386384
rc.runner_mode = 'subprocess'
387385
assert rc._should_allocate_tty() is False
388386

389387

390388
def test_should_allocate_tty_subprocess_both_tty(tmp_path, mocker):
391-
"""subprocess mode with both input_fd and output_fd as TTY allocates TTY."""
392389
rc = BaseConfig(private_data_dir=str(tmp_path))
393390
rc.runner_mode = 'subprocess'
394391
rc.input_fd = mocker.Mock()
@@ -399,11 +396,6 @@ def test_should_allocate_tty_subprocess_both_tty(tmp_path, mocker):
399396

400397

401398
def test_should_allocate_tty_subprocess_input_fd_is_pipe(tmp_path, mocker):
402-
"""subprocess mode with a pipe input_fd does not allocate TTY.
403-
404-
When ansible-navigator runs in CI/CD where stdin is not a terminal,
405-
--tty must not be added to prevent ANSI escape pollution.
406-
"""
407399
rc = BaseConfig(private_data_dir=str(tmp_path))
408400
rc.runner_mode = 'subprocess'
409401
rc.input_fd = mocker.Mock()
@@ -414,13 +406,6 @@ def test_should_allocate_tty_subprocess_input_fd_is_pipe(tmp_path, mocker):
414406

415407

416408
def test_should_allocate_tty_subprocess_output_fd_is_pipe(tmp_path, mocker):
417-
"""subprocess mode with TTY stdin but redirected stdout does not allocate TTY.
418-
419-
This is the exact ansible-navigator#1607 scenario: the user runs
420-
``ansible-navigator config init -m stdout > ansible.cfg`` from a real
421-
terminal. stdin is a TTY but stdout is redirected to a file.
422-
--tty must not be added to prevent ANSI escapes in the output.
423-
"""
424409
rc = BaseConfig(private_data_dir=str(tmp_path))
425410
rc.runner_mode = 'subprocess'
426411
rc.input_fd = mocker.Mock()

test/unit/config/test_command.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ def test_prepare_run_command_with_containerization(tmp_path, runtime, mocker):
128128

129129
@pytest.mark.parametrize('runtime', ('docker', 'podman'))
130130
def test_prepare_run_command_containerized_subprocess_no_tty_when_piped(tmp_path, runtime, mocker):
131-
"""Reproduce ansible-navigator#1607: when input_fd is not a tty
132-
(output redirected to file), --tty must not appear in container args."""
131+
"""Regression for ansible-navigator#1607: input_fd is not a tty, --tty must not appear."""
133132
mocker.patch.dict('os.environ', {'HOME': str(tmp_path)}, clear=True)
134133
tmp_path.joinpath('.ssh').mkdir()
135134

@@ -156,7 +155,7 @@ def test_prepare_run_command_containerized_subprocess_no_tty_when_piped(tmp_path
156155

157156
@pytest.mark.parametrize('runtime', ('docker', 'podman'))
158157
def test_prepare_run_command_containerized_subprocess_tty_when_interactive(tmp_path, runtime, mocker):
159-
"""When both input_fd and output_fd are real terminals, --tty should be present."""
158+
"""Both input_fd and output_fd are real terminals, --tty should be present."""
160159
mocker.patch.dict('os.environ', {'HOME': str(tmp_path)}, clear=True)
161160
tmp_path.joinpath('.ssh').mkdir()
162161

@@ -185,8 +184,7 @@ def test_prepare_run_command_containerized_subprocess_tty_when_interactive(tmp_p
185184

186185
@pytest.mark.parametrize('runtime', ('docker', 'podman'))
187186
def test_prepare_run_command_containerized_subprocess_no_tty_when_stdout_redirected(tmp_path, runtime, mocker):
188-
"""Reproduce ansible-navigator#1607: stdin is a TTY but stdout is
189-
redirected to a file (``> ansible.cfg``). --tty must not appear."""
187+
"""Regression for ansible-navigator#1607: stdin is TTY but stdout is redirected, --tty must not appear."""
190188
mocker.patch.dict('os.environ', {'HOME': str(tmp_path)}, clear=True)
191189
tmp_path.joinpath('.ssh').mkdir()
192190

@@ -215,7 +213,7 @@ def test_prepare_run_command_containerized_subprocess_no_tty_when_stdout_redirec
215213

216214
@pytest.mark.parametrize('runtime', ('docker', 'podman'))
217215
def test_prepare_run_command_containerized_subprocess_no_tty_without_input_fd(tmp_path, runtime, mocker):
218-
"""Without input_fd (AWX/Controller), subprocess mode should not get --tty."""
216+
"""Without input_fd (AWX/Controller scenario), subprocess mode should not get --tty."""
219217
mocker.patch.dict('os.environ', {'HOME': str(tmp_path)}, clear=True)
220218
tmp_path.joinpath('.ssh').mkdir()
221219

0 commit comments

Comments
 (0)