Skip to content

Commit fc789ec

Browse files
committed
docs(pytest_plugin) Add TempServer
1 parent 6a42a33 commit fc789ec

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/pytest-plugin/index.md

+28
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ def test_something(session):
9393

9494
The above will assure the libtmux session launches with `-x 800 -y 600`.
9595

96+
(temp_server)=
97+
98+
### Creating temporary servers
99+
100+
If you need multiple independent tmux servers in your tests, the {func}`TempServer fixture <libtmux.pytest_plugin.TempServer>` provides a factory that creates servers with unique socket names. Each server is automatically cleaned up when the test completes.
101+
102+
```python
103+
def test_something(TempServer):
104+
Server = TempServer() # Get unique partial'd Server
105+
server = Server() # Create server instance
106+
107+
session = server.new_session()
108+
assert server.is_alive()
109+
```
110+
111+
You can also use it with custom configurations, similar to the {ref}`server fixture <Setting a tmux configuration>`:
112+
113+
```python
114+
def test_with_config(TempServer, tmp_path):
115+
config_file = tmp_path / "tmux.conf"
116+
config_file.write_text("set -g status off")
117+
118+
Server = TempServer()
119+
server = Server(config_file=str(config_file))
120+
```
121+
122+
This is particularly useful when testing interactions between multiple tmux servers or when you need to verify behavior across server restarts.
123+
96124
(set_home)=
97125

98126
### Setting a temporary home directory

0 commit comments

Comments
 (0)