|
1 | 1 | (pytest_plugin_fixtures)= |
2 | 2 |
|
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 |
4 | 105 |
|
5 | 106 | ```{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. |
12 | 159 | ``` |
0 commit comments