Skip to content

Commit b616fdc

Browse files
committed
test(pane): Make test_capture_pane more robust
why: Test was flaky due to timing issues with shell initialization what: - Add small delay after window creation - Add error handling around capture_pane calls - Increase retry timeouts from 1s to 2s - Add more comprehensive output checks - Add check for non-empty pane contents
1 parent 7a80a7f commit b616fdc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tests/test_pane.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import shutil
7+
import time
78
import typing as t
89

910
import pytest
@@ -74,15 +75,22 @@ def test_capture_pane(session: Session) -> None:
7475
window_name="capture_pane",
7576
window_shell=f"{env} PROMPT_COMMAND='' PS1='READY>' sh",
7677
)
78+
79+
# Give tmux a moment to create the window and start the shell
80+
time.sleep(0.1)
81+
7782
pane = session.active_window.active_pane
7883
assert pane is not None
7984

8085
def wait_for_prompt() -> bool:
81-
pane_contents = "\n".join(pane.capture_pane())
82-
return "READY>" in pane_contents
86+
try:
87+
pane_contents = "\n".join(pane.capture_pane())
88+
return "READY>" in pane_contents and len(pane_contents.strip()) > 0
89+
except Exception:
90+
return False
8391

8492
# Wait for shell to be ready with our custom prompt
85-
retry_until(wait_for_prompt, 1, raises=True)
93+
retry_until(wait_for_prompt, 2, raises=True)
8694

8795
pane_contents = "\n".join(pane.capture_pane())
8896
assert "READY>" in pane_contents
@@ -94,11 +102,18 @@ def wait_for_prompt() -> bool:
94102
)
95103

96104
def wait_for_output() -> bool:
97-
pane_contents = "\n".join(pane.capture_pane())
98-
return "Hello World !" in pane_contents and pane_contents.count("READY>") >= 2
105+
try:
106+
pane_contents = "\n".join(pane.capture_pane())
107+
return (
108+
"Hello World !" in pane_contents
109+
and pane_contents.count("READY>") >= 2
110+
and r'printf "\n%s\n" "Hello World !"' in pane_contents
111+
)
112+
except Exception:
113+
return False
99114

100115
# Wait for command output and new prompt
101-
retry_until(wait_for_output, 1, raises=True)
116+
retry_until(wait_for_output, 2, raises=True)
102117

103118
pane_contents = "\n".join(pane.capture_pane())
104119
assert r'READY>printf "\n%s\n" "Hello World !"' in pane_contents

0 commit comments

Comments
 (0)