Skip to content

Commit ae106b1

Browse files
committed
docs: Improve conftest.py
1 parent 6637780 commit ae106b1

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

conftest.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
"""Conftest.py (root-level).
1+
"""Configure root-level pytest fixtures for libtmux.
22
3-
We keep this in root pytest fixtures in pytest's doctest plugin to be available, as well
4-
as avoiding conftest.py from being included in the wheel, in addition to pytest_plugin
5-
for pytester only being available via the root directory.
3+
We keep this file at the root to make these fixtures available to all
4+
tests, while also preventing unwanted inclusion in the distributed
5+
wheel. Additionally, `pytest_plugins` references ensure that the
6+
`pytester` plugin is accessible for test generation and execution.
67
7-
See "pytest_plugins in non-top-level conftest files" in
8-
https://docs.pytest.org/en/stable/deprecations.html
8+
See Also
9+
--------
10+
pytest_plugins in non-top-level conftest files
11+
https://docs.pytest.org/en/stable/deprecations.html
912
"""
1013

1114
from __future__ import annotations
@@ -35,7 +38,13 @@ def add_doctest_fixtures(
3538
request: pytest.FixtureRequest,
3639
doctest_namespace: dict[str, t.Any],
3740
) -> None:
38-
"""Configure doctest fixtures for pytest-doctest."""
41+
"""Configure doctest fixtures for pytest-doctest.
42+
43+
Automatically sets up tmux-related classes and default fixtures,
44+
making them available in doctest namespaces if `tmux` is found
45+
on the system. This ensures that doctest blocks referencing tmux
46+
structures can execute smoothly in the test environment.
47+
"""
3948
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
4049
request.getfixturevalue("set_home")
4150
doctest_namespace["Server"] = Server
@@ -63,22 +72,26 @@ def set_home(
6372
monkeypatch: pytest.MonkeyPatch,
6473
user_path: pathlib.Path,
6574
) -> None:
66-
"""Configure home directory for pytest tests."""
75+
"""Set the HOME environment variable to the temporary user directory."""
6776
monkeypatch.setenv("HOME", str(user_path))
6877

6978

7079
@pytest.fixture(autouse=True)
7180
def setup_fn(
7281
clear_env: None,
7382
) -> None:
74-
"""Function-level test configuration fixtures for pytest."""
83+
"""Apply function-level test fixture configuration (e.g., environment cleanup)."""
7584

7685

7786
@pytest.fixture(autouse=True, scope="session")
7887
def setup_session(
7988
request: pytest.FixtureRequest,
8089
config_file: pathlib.Path,
8190
) -> None:
82-
"""Session-level test configuration for pytest."""
91+
"""Apply session-level test fixture configuration for libtmux testing.
92+
93+
If zsh is in use, applies a suppressing `.zshrc` fix to avoid
94+
default interactive messages that might disrupt tmux sessions.
95+
"""
8396
if USING_ZSH:
8497
request.getfixturevalue("zshrc")

0 commit comments

Comments
 (0)