From 10deb216bf1b007fc5eb6ef05adda7d101337090 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 22 May 2022 07:24:23 -0500 Subject: [PATCH 1/3] test(test_load_workspace_enter): Use retry to cut down time --- tests/test_workspacebuilder.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index f44d031789f..aeb9a0beeb9 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -190,6 +190,7 @@ def f(): history_cmd = captured_pane.stdout[-2].strip() return assertCase(sent_cmd, history_cmd) + assert retry_until(f), f"Unknown sent command: [{sent_cmd}] in {assertCase}" @@ -329,6 +330,7 @@ def test_window_shell(session): def f(): session.server._update_windows() return w["window_name"] != "top" + retry_until(f) assert w.name != "top" @@ -447,6 +449,7 @@ def test_start_directory(session, tmp_path: pathlib.Path): for path, window in zip(dirs, session.windows): for p in window.panes: + def f(): p.server._update_panes() pane_path = p.current_path @@ -497,6 +500,7 @@ def test_start_directory_relative(session, tmp_path: pathlib.Path): for path, window in zip(dirs, session.windows): for p in window.panes: + def f(): p.server._update_panes() # Handle case where directories resolve to /private/ in OSX @@ -558,6 +562,7 @@ def test_pane_order(session): def f(): p.server._update_panes() return p.current_path == pane_path + retry_until(f) assert p.current_path, pane_path @@ -1014,17 +1019,20 @@ def test_load_workspace_enter( builder = WorkspaceBuilder(sconf=sconfig, server=server) builder.build() - time.sleep(1) - session = builder.session pane = session.attached_pane - captured_pane = "\n".join(pane.capture_pane()) + def fn(): + captured_pane = "\n".join(pane.capture_pane()) - if should_see: - assert output in captured_pane - else: - assert output not in captured_pane + if should_see: + return output in captured_pane + else: + return output not in captured_pane + + assert retry_until( + fn, 1 + ), f'Should{" " if should_see else "not "} output in captured pane' @pytest.mark.parametrize( From 2e19a9bee027deb706969824e93c60ec25e375c1 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 22 May 2022 07:26:56 -0500 Subject: [PATCH 2/3] tests(test_load_workspace_sleep): Use less sleep time --- tests/test_workspacebuilder.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index aeb9a0beeb9..d8593d5c506 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -1046,12 +1046,12 @@ def fn(): - panes: - shell_command: - cmd: echo "___$((1 + 5))___" - sleep_before: 2 + sleep_before: .15 - cmd: echo "___$((1 + 3))___" - sleep_before: 1 + sleep_before: .35 """ ), - 1.5, + 0.5, "___4___", ], [ @@ -1062,12 +1062,12 @@ def fn(): - panes: - shell_command: - cmd: echo "___$((1 + 5))___" - sleep_before: 2 - - cmd: echo "___$((1 + 3))___" sleep_before: 1 + - cmd: echo "___$((1 + 3))___" + sleep_before: .25 """ ), - 3, + 1.25, "___4___", ], [ @@ -1078,10 +1078,10 @@ def fn(): - panes: - shell_command: - cmd: echo "___$((1 + 3))___" - sleep_before: 2 + sleep_before: .5 """ ), - 2, + 0.5, "___4___", ], [ @@ -1092,10 +1092,10 @@ def fn(): - panes: - shell_command: - cmd: echo "___$((1 + 3))___" - sleep_before: 2 + sleep_before: 1 """ ), - 2, + 1, "___4___", ], [ @@ -1104,21 +1104,21 @@ def fn(): session_name: Should not execute shell_command_before: - cmd: echo "sleeping before" - sleep_before: 2 + sleep_before: .5 windows: - panes: - echo "___$((1 + 3))___" """ ), - 2, + 0.5, "___4___", ], ], ids=[ - "command_level_sleep_3_shortform", - "command_level_pane_sleep_3_longform", - "pane_sleep_2_shortform", - "pane_sleep_2_longform", + "command_level_sleep_shortform", + "command_level_pane_sleep_longform", + "pane_sleep_shortform", + "pane_sleep_longform", "shell_before_before_command_level", ], ) From 5424ecde481312271ecba76f26413c3a57e0b1a1 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 22 May 2022 07:35:14 -0500 Subject: [PATCH 3/3] tests: If ZSH is the shell, stub out zshrc to prevent default message --- tests/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index da5d1713a00..dcb37be2041 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,7 @@ from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer logger = logging.getLogger(__name__) +USING_ZSH = "zsh" in os.getenv("SHELL", "") @pytest.fixture(autouse=True, scope="session") @@ -24,6 +25,18 @@ def user_path(home_path: pathlib.Path): return p +@pytest.mark.skipif(USING_ZSH, reason="Using ZSH") +@pytest.fixture(autouse=USING_ZSH, scope="session") +def zshrc(user_path: pathlib.Path): + """This quiets ZSH default message. + + Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin. + """ + p = user_path / ".zshrc" + p.touch() + return p + + @pytest.fixture(autouse=True) def home_path_default(user_path: pathlib.Path): os.environ["HOME"] = str(user_path)