Skip to content

Commit 32038c4

Browse files
committed
docs(pytest-plugin): Add control sandbox fixture usage
1 parent ba7b9fa commit 32038c4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/pytest-plugin/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ def test_my_flow(server, engine_name):
162162
`TestServer` also respects the selected engine. Control mode is experimental and
163163
its APIs may change between releases.
164164

165+
### Control sandbox fixture (experimental)
166+
167+
Use ``control_sandbox`` when you need a hermetic control-mode server for a test:
168+
169+
```python
170+
import typing as t
171+
import pytest
172+
from libtmux.server import Server
173+
174+
@pytest.mark.engines(["control"])
175+
def test_control_sandbox(control_sandbox: t.ContextManager[Server]):
176+
with control_sandbox as server:
177+
session = server.new_session(session_name="sandbox", attach=False)
178+
out = server.cmd("display-message", "-p", "hi")
179+
assert out.stdout == ["hi"]
180+
```
181+
182+
The fixture:
183+
- Spins up a unique socket name and isolates ``HOME`` / ``TMUX_TMPDIR``
184+
- Clears inherited ``TMUX`` so it never attaches to the user's server
185+
- Uses ``ControlModeEngine`` and cleans up the server on exit
186+
165187
## Fixtures
166188

167189
```{eval-rst}

0 commit comments

Comments
 (0)