You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pytest-plugin/index.md
+28
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,34 @@ def test_something(session):
93
93
94
94
The above will assure the libtmux session launches with `-x 800 -y 600`.
95
95
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
+
deftest_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
+
deftest_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.
0 commit comments