Skip to content

Commit da00754

Browse files
committed
1 parent b9299a2 commit da00754

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

.cursor/rules/tmuxp-pytest.mdc

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
description: Guidelines for using pytest with tmuxp, including libtmux fixtures
3+
globs: tests/**/test_*.py
4+
alwaysApply: true
5+
---
6+
7+
# tmuxp Pytest Guidelines
8+
9+
## Leveraging libtmux fixtures
10+
11+
tmuxp tests can utilize libtmux's pytest fixtures for fast, efficient tmux server, session, window, and pane setup/teardown. These fixtures automatically manage the lifecycle of tmux resources during tests.
12+
13+
### Available fixtures
14+
15+
The following fixtures are available through libtmux's pytest plugin:
16+
17+
- `server`: Creates a temporary tmux server with isolated socket
18+
- `session`: Creates a temporary tmux session in the server
19+
- `window`: Creates a temporary tmux window in the session
20+
- `pane`: Creates a temporary tmux pane in the pane
21+
- `TestServer`: Factory for creating multiple independent servers with unique socket names
22+
23+
### Usage in tests
24+
25+
```python
26+
def test_something_with_server(server):
27+
# server is already running with proper configuration
28+
my_session = server.new_session("test-session")
29+
assert server.is_alive()
30+
assert my_session in server.sessions
31+
32+
def test_something_with_session(session):
33+
# session is already created and configured
34+
new_window = session.new_window("test-window")
35+
assert new_window in session.windows
36+
37+
def test_with_multiple_servers(TestServer):
38+
# Create independent servers for comparison tests
39+
Server1 = TestServer()
40+
Server2 = TestServer()
41+
42+
server1 = Server1()
43+
server2 = Server2()
44+
45+
session1 = server1.new_session()
46+
session2 = server2.new_session()
47+
48+
assert server1.socket_path != server2.socket_path
49+
```
50+
51+
### Customizing session parameters
52+
53+
You can override the `session_params` fixture to customize session creation:
54+
55+
```python
56+
import pytest
57+
58+
@pytest.fixture
59+
def session_params():
60+
return {
61+
'x': 800,
62+
'y': 600,
63+
'window_name': 'custom-window'
64+
}
65+
```
66+
67+
### Benefits
68+
69+
- No need to manually set up and tear down tmux infrastructure
70+
- Tests run in isolated tmux environments
71+
- Faster test execution
72+
- Reliable test environment with predictable configuration
73+
- Multiple tests can run in parallel without tmux session conflicts
74+
75+
For more details, see:
76+
- [libtmux pytest plugin documentation](https://libtmux.git-pull.com/pytest-plugin/index.html)
77+
- [libtmux pytest plugin code](https://github.com/tmux-python/libtmux/blob/master/src/libtmux/pytest_plugin.py)

.windsurfrules

+35-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,41 @@
114114

115115
<pytest_testing_guidelines>
116116
- Use fixtures from conftest.py instead of monkeypatch and MagicMock when available
117-
- For instance, if using libtmux, use provided fixtures: server, session, window, and pane
117+
- For libtmux tests, use these provided fixtures for fast, efficient tmux resource management:
118+
- `server`: Creates a temporary tmux server with isolated socket
119+
- `session`: Creates a temporary tmux session in the server
120+
- `window`: Creates a temporary tmux window in the session
121+
- `pane`: Creates a temporary tmux pane in the pane
122+
- `TestServer`: Factory for creating multiple independent servers with unique socket names
123+
- Example usage with server fixture:
124+
```python
125+
def test_something_with_server(server):
126+
# server is already running with proper configuration
127+
my_session = server.new_session("test-session")
128+
assert server.is_alive()
129+
```
130+
- Example usage with session fixture:
131+
```python
132+
def test_something_with_session(session):
133+
# session is already created and configured
134+
new_window = session.new_window("test-window")
135+
assert new_window in session.windows
136+
```
137+
- Customize session parameters by overriding the session_params fixture:
138+
```python
139+
@pytest.fixture
140+
def session_params():
141+
return {
142+
'x': 800,
143+
'y': 600,
144+
'window_name': 'custom-window'
145+
}
146+
```
147+
- Benefits of using libtmux fixtures:
148+
- No need to manually set up and tear down tmux infrastructure
149+
- Tests run in isolated tmux environments
150+
- Faster test execution
151+
- Reliable test environment with predictable configuration
118152
- Document in test docstrings why standard fixtures weren't used for exceptional cases
119153
- Use tmp_path (pathlib.Path) fixture over Python's tempfile
120154
- Use monkeypatch fixture over unittest.mock

0 commit comments

Comments
 (0)