Skip to content

Commit 1c37446

Browse files
committed
docs(pytest-plugin): restructure fixture reference with autofixture directives
why: The previous fixture reference used a single automodule dump that rendered fixtures as plain functions. The new page uses autofixture directives to show fixtures grouped by purpose (core, environment, override hooks, factories) with a decision guide and configuration reference. what: - Rewrite docs/api/testing/pytest-plugin/fixtures.md with Quick Start section, "Which Fixture Do I Need?" guide, autofixture-index table, grouped autofixture directives with inline examples, and confval configuration reference - Update docs/api/testing/pytest-plugin/usage.md to change {func} xrefs to {fixture} xrefs (home_path, user_path, config_file, session, server, session_params, TestServer) to match the new domain objects
1 parent 0e21fc8 commit 1c37446

2 files changed

Lines changed: 161 additions & 14 deletions

File tree

Lines changed: 154 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,159 @@
11
(pytest_plugin_fixtures)=
22

3-
# Fixture Reference
3+
# Fixtures
4+
5+
## Quick Start
6+
7+
Add a fixture name as a test parameter — pytest creates and injects it automatically. You never call fixtures yourself.
8+
9+
```python
10+
def test_basic(server: Server) -> None:
11+
session = server.new_session(session_name="my-session")
12+
assert session is not None
13+
14+
15+
def test_with_session(session: Session) -> None:
16+
window = session.new_window(window_name="test")
17+
assert window is not None
18+
```
19+
20+
## Which Fixture Do I Need?
21+
22+
- Use {fixture}`session` when you want a ready-to-use tmux session.
23+
- Use {fixture}`server` when you want a bare server and will create sessions yourself.
24+
- Use {fixture}`TestServer` when you need multiple isolated servers in one test.
25+
- Override {fixture}`session_params` when you need custom session creation.
26+
- Override {fixture}`home_user_name` when you need a custom test user.
27+
- Request {fixture}`clear_env` when testing tmux behavior with a minimal environment.
28+
29+
## Fixture Summary
30+
31+
```{autofixture-index} libtmux.pytest_plugin
32+
```
33+
34+
---
35+
36+
## Core Fixtures
37+
38+
The primary injection points for libtmux tests.
39+
40+
```{eval-rst}
41+
.. autofixture:: libtmux.pytest_plugin.server
42+
43+
.. rubric:: Example
44+
45+
.. code-block:: python
46+
47+
def test_server_sessions(server: Server) -> None:
48+
session = server.new_session(session_name="work")
49+
assert session.session_name == "work"
50+
51+
.. autofixture:: libtmux.pytest_plugin.session
52+
53+
.. rubric:: Example
54+
55+
.. code-block:: python
56+
57+
def test_session_windows(session: Session) -> None:
58+
window = session.new_window(window_name="editor")
59+
assert window.window_name == "editor"
60+
```
61+
62+
## Environment Fixtures
63+
64+
Session-scoped fixtures that create an isolated filesystem environment.
65+
Shared across all tests in a session — created once, reused everywhere.
66+
67+
```{eval-rst}
68+
.. autofixture:: libtmux.pytest_plugin.home_path
69+
70+
.. autofixture:: libtmux.pytest_plugin.user_path
71+
72+
.. autofixture:: libtmux.pytest_plugin.config_file
73+
74+
.. autofixture:: libtmux.pytest_plugin.zshrc
75+
```
76+
77+
## Override Hooks
78+
79+
Override these in your project's `conftest.py` to customise the test environment.
80+
81+
```{eval-rst}
82+
.. autofixture:: libtmux.pytest_plugin.home_user_name
83+
:kind: override_hook
84+
85+
.. autofixture:: libtmux.pytest_plugin.session_params
86+
:kind: override_hook
87+
88+
.. rubric:: Example
89+
90+
.. code-block:: python
91+
92+
# conftest.py
93+
@pytest.fixture
94+
def session_params() -> dict:
95+
return {"x": 800, "y": 600}
96+
```
97+
98+
## Factories
99+
100+
```{eval-rst}
101+
.. autofixture:: libtmux.pytest_plugin.TestServer
102+
```
103+
104+
## Low-Level / Rarely Needed
4105

5106
```{eval-rst}
6-
.. automodule:: libtmux.pytest_plugin
7-
:members:
8-
:inherited-members:
9-
:private-members:
10-
:show-inheritance:
11-
:member-order: bysource
107+
.. autofixture:: libtmux.pytest_plugin.clear_env
108+
```
109+
110+
---
111+
112+
## Configuration
113+
114+
These `conf.py` values control how fixture documentation is rendered:
115+
116+
```{eval-rst}
117+
.. confval:: pytest_fixture_hidden_dependencies
118+
119+
Fixture names to suppress from "Depends on" lists. Default: common pytest
120+
builtins (:external+pytest:std:fixture:`pytestconfig`,
121+
:external+pytest:std:fixture:`capfd`,
122+
:external+pytest:std:fixture:`capsysbinary`,
123+
:external+pytest:std:fixture:`capfdbinary`,
124+
:external+pytest:std:fixture:`recwarn`,
125+
:external+pytest:std:fixture:`tmpdir`,
126+
:external+pytest:std:fixture:`pytester`,
127+
:external+pytest:std:fixture:`testdir`,
128+
:external+pytest:std:fixture:`record_property`,
129+
``record_xml_attribute``,
130+
:external+pytest:std:fixture:`record_testsuite_property`,
131+
:external+pytest:std:fixture:`cache`).
132+
133+
.. confval:: pytest_fixture_builtin_links
134+
135+
URL mapping for builtin fixture external links in "Depends on" blocks.
136+
Default: links to pytest docs for
137+
:external+pytest:std:fixture:`tmp_path_factory`,
138+
:external+pytest:std:fixture:`tmp_path`,
139+
:external+pytest:std:fixture:`monkeypatch`,
140+
:external+pytest:std:fixture:`request`,
141+
:external+pytest:std:fixture:`capsys`,
142+
:external+pytest:std:fixture:`caplog`.
143+
144+
.. confval:: pytest_external_fixture_links
145+
146+
URL mapping for external fixture cross-references. Default: ``{}``.
147+
```
148+
149+
---
150+
151+
```{note}
152+
All fixtures above are also auto-discoverable via:
153+
154+
.. autofixtures:: libtmux.pytest_plugin
155+
:order: source
156+
157+
Use ``autofixtures::`` in your own plugin docs to document all fixtures from a
158+
module without listing each one manually.
12159
```

docs/api/testing/pytest-plugin/usage.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ passed into your test.
4646
These fixtures are automatically used when the plugin is enabled and `pytest` is run.
4747

4848
- Creating temporary, test directories for:
49-
- `/home/` ({func}`home_path`)
50-
- `/home/${user}` ({func}`user_path`)
51-
- Default `.tmux.conf` configuration with these settings ({func}`config_file`):
49+
- `/home/` ({fixture}`home_path`)
50+
- `/home/${user}` ({fixture}`user_path`)
51+
- Default `.tmux.conf` configuration with these settings ({fixture}`config_file`):
5252

5353
- `base-index -g 1`
5454

@@ -58,19 +58,19 @@ These fixtures are automatically used when the plugin is enabled and `pytest` is
5858

5959
## Setting a tmux configuration
6060

61-
If you would like {func}`session fixture <libtmux.pytest_plugin.session>` to automatically use a configuration, you have a few
61+
If you would like {fixture}`session <libtmux.pytest_plugin.session>` to automatically use a configuration, you have a few
6262
options:
6363

6464
- Pass a `config_file` into {class}`~libtmux.Server`
6565
- Set the `HOME` directory to a local or temporary pytest path with a configuration file
6666

67-
You could also read the code and override {func}`server fixture <libtmux.pytest_plugin.server>` in your own doctest.
67+
You could also read the code and override {fixture}`server <libtmux.pytest_plugin.server>` in your own doctest.
6868

6969
(custom_session_params)=
7070

7171
### Custom session parameters
7272

73-
You can override `session_params` to customize the `session` fixture. The
73+
You can override {fixture}`session_params` to customize the `session` fixture. The
7474
dictionary will directly pass into {meth}`Server.new_session` keyword arguments.
7575

7676
```python
@@ -94,7 +94,7 @@ The above will assure the libtmux session launches with `-x 800 -y 600`.
9494

9595
### Creating temporary servers
9696

97-
If you need multiple independent tmux servers in your tests, the {func}`TestServer fixture <libtmux.pytest_plugin.TestServer>` provides a factory that creates servers with unique socket names. Each server is automatically cleaned up when the test completes.
97+
If you need multiple independent tmux servers in your tests, the {fixture}`TestServer <libtmux.pytest_plugin.TestServer>` provides a factory that creates servers with unique socket names. Each server is automatically cleaned up when the test completes.
9898

9999
```python
100100
def test_something(TestServer):

0 commit comments

Comments
 (0)