|
| 1 | +import pathlib |
| 2 | +import shutil |
| 3 | +import typing as t |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from _pytest.doctest import DoctestItem |
| 8 | + |
| 9 | +from libtmux.pytest_plugin import USING_ZSH |
| 10 | + |
| 11 | +if t.TYPE_CHECKING: |
| 12 | + from libtmux.session import Session |
| 13 | + |
1 | 14 | pytest_plugins = ["pytester"]
|
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture(autouse=True) |
| 18 | +def add_doctest_fixtures( |
| 19 | + request: pytest.FixtureRequest, |
| 20 | + doctest_namespace: t.Dict[str, t.Any], |
| 21 | +) -> None: |
| 22 | + if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"): |
| 23 | + request.getfixturevalue("set_home") |
| 24 | + doctest_namespace["server"] = request.getfixturevalue("server") |
| 25 | + session: "Session" = request.getfixturevalue("session") |
| 26 | + doctest_namespace["session"] = session |
| 27 | + doctest_namespace["window"] = session.attached_window |
| 28 | + doctest_namespace["pane"] = session.attached_pane |
| 29 | + doctest_namespace["request"] = request |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture(autouse=True, scope="function") |
| 33 | +def set_home( |
| 34 | + monkeypatch: pytest.MonkeyPatch, |
| 35 | + user_path: pathlib.Path, |
| 36 | +) -> None: |
| 37 | + monkeypatch.setenv("HOME", str(user_path)) |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture(autouse=True, scope="session") |
| 41 | +@pytest.mark.usefixtures("clear_env") |
| 42 | +def setup( |
| 43 | + request: pytest.FixtureRequest, |
| 44 | + config_file: pathlib.Path, |
| 45 | +) -> None: |
| 46 | + if USING_ZSH: |
| 47 | + request.getfixturevalue("zshrc") |
0 commit comments