Fixture Reference¶

libtmux pytest plugin.

libtmux.pytest_plugin.home_path(tmp_path_factory)[source]¶

Temporary /home/ path.

Return type:

Path

Parameters:

tmp_path_factory (TempPathFactory)

libtmux.pytest_plugin.home_user_name()[source]¶

Return default username to set for user_path() fixture.

Return type:

str

libtmux.pytest_plugin.user_path(home_path, home_user_name)[source]¶

Ensure and return temporary user directory.

Used by: config_file(), zshrc()

Note: You will need to set the home directory, see Setting a temporary home directory.

Return type:

Path

Parameters:
  • home_path (Path)

  • home_user_name (str)

libtmux.pytest_plugin.zshrc(user_path)[source]¶

Suppress ZSH default message.

Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin.

Return type:

Path

Parameters:

user_path (Path)

libtmux.pytest_plugin.config_file(user_path)[source]¶

Return fixture for .tmux.conf configuration.

  • base-index -g 1

These guarantee pane and windows targets can be reliably referenced and asserted.

Note: You will need to set the home directory, see Setting a temporary home directory.

Return type:

Path

Parameters:

user_path (Path)

libtmux.pytest_plugin.clear_env(monkeypatch)[source]¶

Clear out any unnecessary environment variables that could interrupt tests.

tmux show-environment tests were being interrupted due to a lot of crazy env vars.

Return type:

None

Parameters:

monkeypatch (MonkeyPatch)

libtmux.pytest_plugin.server(request, monkeypatch, config_file)[source]¶

Return new, temporary libtmux.Server.

Return type:

Server

Parameters:
>>> from libtmux.server import Server
>>> def test_example(server: Server) -> None:
...     assert isinstance(server, Server)
...     session = server.new_session('my session')
...     assert len(server.sessions) == 1
...     assert [session.name.startswith('my') for session in server.sessions]
libtmux.pytest_plugin.session_params()[source]¶

Return new, temporary libtmux.Session.

Return type:

dict[str, Any]

>>> import pytest
>>> from libtmux.session import Session
>>> @pytest.fixture
... def session_params(session_params):
...     return {
...         'x': 800,
...         'y': 600,
...     }
>>> def test_example(session: "Session") -> None:
...     assert isinstance(session.name, str)
...     assert session.name.startswith('libtmux_')
...     window = session.new_window(window_name='new one')
...     assert window.name == 'new one'
libtmux.pytest_plugin.session(request, session_params, server)[source]¶

Return new, temporary libtmux.Session.

Return type:

Session

Parameters:
>>> from libtmux.session import Session
>>> def test_example(session: "Session") -> None:
...     assert isinstance(session.name, str)
...     assert session.name.startswith('libtmux_')
...     window = session.new_window(window_name='new one')
...     assert window.name == 'new one'
libtmux.pytest_plugin.TestServer(request)[source]¶

Create a temporary tmux server that cleans up after itself.

This is similar to the server pytest fixture, but can be used outside of pytest. The server will be killed when the test completes.

Return type:

type[Server]

Returns:

A factory function that returns a Server with a unique socket_name

Return type:

type[Server]

Parameters:

request (FixtureRequest)

Examples

>>> server = Server()  # Create server instance
>>> server.new_session()
Session($... ...)
>>> server.is_alive()
True
>>> # Each call creates a new server with unique socket
>>> server2 = Server()
>>> server2.socket_name != server.socket_name
True