Temporary Objects

Context managers for temporary tmux objects (sessions, windows).

Temporary object helpers for libtmux and downstream libtmux libraries.

libtmux.test.temporary.temp_session(server, session_name=None, kill_session=False, attach=False, start_directory=None, window_name=None, window_command=None, x=None, y=None, environment=None, *args, detach_others=None, no_size=None, client_flags=None, **kwargs)
function[source]
function[source]
libtmux.test.temporary.temp_session(server, session_name=None, kill_session=False, attach=False, start_directory=None, window_name=None, window_command=None, x=None, y=None, environment=None, *args, detach_others=None, no_size=None, client_flags=None, **kwargs)

Return a context manager with a temporary session.

If no session_name is entered, get_test_session_name() will make an unused session name.

The session will destroy itself upon closing with Session.session().

Parameters:
Yields:

libtmux.Session – Temporary session

Return type:

Generator[Session, None, None]

Examples

>>> with temp_session(server) as session:
...     session.new_window(window_name='my window')
Window(@3 2:my window, Session($... ...))
libtmux.test.temporary.temp_window(session, window_name=None, *, start_directory=None, attach=False, window_index='', window_shell=None, environment=None, direction=None, target_window=None, kill_existing=None, select_existing=None)
function[source]
function[source]
libtmux.test.temporary.temp_window(session, window_name=None, *, start_directory=None, attach=False, window_index='', window_shell=None, environment=None, direction=None, target_window=None, kill_existing=None, select_existing=None)

Return a context manager with a temporary window.

The window will destroy itself upon closing with window. kill().

If no window_name is entered, get_test_window_name() will make an unused window name.

Parameters:
Yields:

libtmux.Window – temporary window

Return type:

Generator[Window, None, None]

Examples

>>> with temp_window(session) as window:
...     window
Window(@2 2:... Session($1 libtmux_...))
>>> with temp_window(session) as window:
...     window.split()
Pane(%4 Window(@3 2:libtmux_..., Session($1 libtmux_...)))