Debian Codegraph @

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

raw symbols SCIP
1 (pytest_plugin_fixtures)=
2
3 # Fixtures
4
5 ## Quick Start
6
7 Add a fixture name as a test parameter — [pytest] creates and injects it
8 automatically. You never call fixtures yourself. In doctests, libtmux injects
9 the same objects through `doctest_namespace`:
10
11 ```python
12 >>> created_session = server.new_session(session_name="my-session")
13 >>> created_session is not None
14 True
15 >>> created_session.kill()
16
17 >>> created_window = session.new_window(window_name="test")
18 >>> created_window is not None
19 True
20 >>> created_window.kill()
21 ```
22
23 ## Which Fixture Do I Need?
24
25 - Use {fixture}`session` when you want a ready-to-use tmux session.
26 - Use {fixture}`server` when you want a bare server and will create sessions yourself.
27 - Use {fixture}`TestServer` when you need multiple isolated servers in one test.
28 - Override {fixture}`session_params` when you need custom session creation.
29 - Override {fixture}`home_user_name` when you need a custom test user.
30 - Request {fixture}`clear_env` when testing tmux behavior with a minimal environment.
31
32 ## Fixture Summary
33
34 | Fixture | Use |
35 |---------|-----|
36 | {fixture}`server` | Bare isolated server |
37 | {fixture}`session` | Ready-to-use isolated session |
38 | {fixture}`home_path` / {fixture}`user_path` | Temporary home directories |
39 | {fixture}`config_file` | Test `.tmux.conf` |
40 | {fixture}`session_params` | Session creation override |
41 | {fixture}`TestServer` | Factory for extra isolated servers |
42 | {fixture}`control_mode` | Attached client factory |
43 | {fixture}`clear_env` | Minimal test environment |
44
45 ---
46
47 ## Core Fixtures
48
49 The primary injection points for libtmux tests.
50
51 ```{eval-rst}
52 .. autofixture:: libtmux.pytest_plugin.server
53
54 .. autofixture:: libtmux.pytest_plugin.session
55 ```
56
57 ## Environment Fixtures
58
59 Session-scoped fixtures that create an isolated filesystem environment.
60 Shared across all tests in a session — created once, reused everywhere.
61
62 ```{eval-rst}
63 .. autofixture:: libtmux.pytest_plugin.home_path
64
65 .. autofixture:: libtmux.pytest_plugin.user_path
66
67 .. autofixture:: libtmux.pytest_plugin.config_file
68
69 .. autofixture:: libtmux.pytest_plugin.zshrc
70 ```
71
72 ## Override Hooks
73
74 Override these in your project's `conftest.py` to customise the test environment.
75
76 ```{eval-rst}
77 .. autofixture:: libtmux.pytest_plugin.home_user_name
78 :kind: override_hook
79
80 .. autofixture:: libtmux.pytest_plugin.session_params
81 :kind: override_hook
82
83 ```
84
85 ## Factories
86
87 ```{eval-rst}
88 .. autofixture:: libtmux.pytest_plugin.TestServer
89
90 .. autofixture:: libtmux.pytest_plugin.control_mode
91
92 ```
93
94 ## Low-Level / Rarely Needed
95
96 ```{eval-rst}
97 .. autofixture:: libtmux.pytest_plugin.clear_env
98 ```
99
100 ---
101
102 ## Configuration
103
104 These `conf.py` values control how fixture documentation is rendered:
105
106 ```{eval-rst}
107 .. confval:: pytest_fixture_hidden_dependencies
108
109 Fixture names to suppress from "Depends on" lists. Default: common pytest
110 builtins (:external+pytest:std:fixture:`pytestconfig`,
111 :external+pytest:std:fixture:`capfd`,
112 :external+pytest:std:fixture:`capsysbinary`,
113 :external+pytest:std:fixture:`capfdbinary`,
114 :external+pytest:std:fixture:`recwarn`,
115 :external+pytest:std:fixture:`tmpdir`,
116 :external+pytest:std:fixture:`pytester`,
117 :external+pytest:std:fixture:`testdir`,
118 :external+pytest:std:fixture:`record_property`,
119 ``record_xml_attribute``,
120 :external+pytest:std:fixture:`record_testsuite_property`,
121 :external+pytest:std:fixture:`cache`).
122
123 .. confval:: pytest_fixture_builtin_links
124
125 URL mapping for builtin fixture external links in "Depends on" blocks.
126 Default: links to pytest docs for
127 :external+pytest:std:fixture:`tmp_path_factory`,
128 :external+pytest:std:fixture:`tmp_path`,
129 :external+pytest:std:fixture:`monkeypatch`,
130 :external+pytest:std:fixture:`request`,
131 :external+pytest:std:fixture:`capsys`,
132 :external+pytest:std:fixture:`caplog`.
133
134 .. confval:: pytest_external_fixture_links
135
136 URL mapping for external fixture cross-references. Default: ``{}``.
137 ```
138
139 ---
140
141 ```{note}
142 All fixtures above are also auto-discoverable via:
143
144 .. autofixtures:: libtmux.pytest_plugin
145 :order: source
146
147 Use ``autofixtures::`` in your own plugin docs to document all fixtures from a
148 module without listing each one manually.
149 ```
150
151 [pytest]: https://docs.pytest.org/en/stable/