Skip to content

Commit 2aa5408

Browse files
committed
pytest plugin: Add default tmux configuration
1 parent 0730248 commit 2aa5408

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

libtmux/pytest_plugin.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import getpass
12
import logging
23
import os
4+
import pathlib
35
import shutil
46
import typing as t
57

@@ -17,6 +19,47 @@
1719
from libtmux.session import Session
1820

1921
logger = logging.getLogger(__name__)
22+
USING_ZSH = "zsh" in os.getenv("SHELL", "")
23+
24+
25+
@pytest.fixture(autouse=True, scope="session")
26+
def home_path(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
27+
return tmp_path_factory.mktemp("home")
28+
29+
30+
@pytest.fixture(autouse=True, scope="session")
31+
def user_path(home_path: pathlib.Path) -> pathlib.Path:
32+
p = home_path / getpass.getuser()
33+
p.mkdir()
34+
return p
35+
36+
37+
@pytest.mark.skipif(USING_ZSH, reason="Using ZSH")
38+
@pytest.fixture(autouse=USING_ZSH, scope="session")
39+
def zshrc(user_path: pathlib.Path) -> pathlib.Path:
40+
"""This quiets ZSH default message.
41+
42+
Needs a startup file .zshenv, .zprofile, .zshrc, .zlogin.
43+
"""
44+
p = user_path / ".zshrc"
45+
p.touch()
46+
return p
47+
48+
49+
@pytest.fixture(scope="function")
50+
def config_file(user_path: pathlib.Path) -> pathlib.Path:
51+
"""Set default tmux configuration (base indexes for windows, panes)
52+
53+
We need this for tests to work across tmux versions in our CI matrix.
54+
"""
55+
c = user_path / ".tmux.conf"
56+
c.write_text(
57+
"""
58+
set -g base-index 1
59+
""",
60+
encoding="utf-8",
61+
)
62+
return c
2063

2164

2265
@pytest.fixture(autouse=True)
@@ -48,9 +91,10 @@ def clear_env(monkeypatch: MonkeyPatch) -> None:
4891

4992

5093
@pytest.fixture(scope="function")
51-
def server(request: SubRequest, monkeypatch: MonkeyPatch) -> Server:
52-
53-
t = Server()
94+
def server(
95+
request: SubRequest, monkeypatch: MonkeyPatch, config_file: pathlib.Path
96+
) -> Server:
97+
t = Server(config_file=str(config_file.absolute()))
5498
t.socket_name = "libtmux_test%s" % next(namer)
5599

56100
def fin() -> None:

0 commit comments

Comments
 (0)