2
2
import logging
3
3
import os
4
4
import pathlib
5
- import shutil
6
5
import typing as t
7
6
8
7
import pytest
9
8
10
- from _pytest .doctest import DoctestItem
11
9
from _pytest .fixtures import SubRequest
12
10
from _pytest .monkeypatch import MonkeyPatch
13
11
22
20
USING_ZSH = "zsh" in os .getenv ("SHELL" , "" )
23
21
24
22
25
- @pytest .fixture (autouse = True , scope = "session" )
23
+ @pytest .fixture (scope = "session" )
26
24
def home_path (tmp_path_factory : pytest .TempPathFactory ) -> pathlib .Path :
25
+ """Temporary `/home/` path."""
27
26
return tmp_path_factory .mktemp ("home" )
28
27
29
28
30
- @pytest .fixture (autouse = True , scope = "session" )
31
- def user_path (home_path : pathlib .Path ) -> pathlib .Path :
32
- p = home_path / getpass .getuser ()
29
+ @pytest .fixture (scope = "session" )
30
+ def home_user_name () -> str :
31
+ """Default username to set for :func:`user_path` fixture."""
32
+ return getpass .getuser ()
33
+
34
+
35
+ @pytest .fixture (scope = "session" )
36
+ def user_path (home_path : pathlib .Path , home_user_name : str ) -> pathlib .Path :
37
+ """Default temporary user directory.
38
+
39
+ Used by:
40
+
41
+ - :func:`config_file`
42
+
43
+ Note: You will need to set the home directory, see :ref:`set_home`.
44
+ """
45
+ p = home_path / home_user_name
33
46
p .mkdir ()
34
47
return p
35
48
36
49
37
50
@pytest .mark .skipif (USING_ZSH , reason = "Using ZSH" )
38
- @pytest .fixture (autouse = USING_ZSH , scope = "session" )
51
+ @pytest .fixture (scope = "session" )
39
52
def zshrc (user_path : pathlib .Path ) -> pathlib .Path :
40
53
"""This quiets ZSH default message.
41
54
@@ -46,11 +59,15 @@ def zshrc(user_path: pathlib.Path) -> pathlib.Path:
46
59
return p
47
60
48
61
49
- @pytest .fixture (scope = "function " )
62
+ @pytest .fixture (scope = "session " )
50
63
def config_file (user_path : pathlib .Path ) -> pathlib .Path :
51
- """Set default tmux configuration (base indexes for windows, panes)
64
+ """Default `.tmux.conf` configuration.
65
+
66
+ - ``base-index -g 1``
67
+
68
+ These guarantee pane and windows targets can be reliably referenced and asserted.
52
69
53
- We need this for tests to work across tmux versions in our CI matrix .
70
+ Note: You will need to set the home directory, see :ref:`set_home` .
54
71
"""
55
72
c = user_path / ".tmux.conf"
56
73
c .write_text (
@@ -62,7 +79,7 @@ def config_file(user_path: pathlib.Path) -> pathlib.Path:
62
79
return c
63
80
64
81
65
- @pytest .fixture ( autouse = True )
82
+ @pytest .fixture
66
83
def clear_env (monkeypatch : MonkeyPatch ) -> None :
67
84
"""Clear out any unnecessary environment variables that could interrupt tests.
68
85
@@ -94,7 +111,7 @@ def clear_env(monkeypatch: MonkeyPatch) -> None:
94
111
def server (
95
112
request : SubRequest , monkeypatch : MonkeyPatch , config_file : pathlib .Path
96
113
) -> Server :
97
- t = Server (config_file = str ( config_file . absolute ()) )
114
+ t = Server ()
98
115
t .socket_name = "libtmux_test%s" % next (namer )
99
116
100
117
def fin () -> None :
@@ -146,16 +163,3 @@ def session(request: SubRequest, server: Server) -> "Session":
146
163
assert TEST_SESSION_NAME != "tmuxp"
147
164
148
165
return session
149
-
150
-
151
- @pytest .fixture (autouse = True )
152
- def add_doctest_fixtures (
153
- request : SubRequest ,
154
- doctest_namespace : t .Dict [str , t .Any ],
155
- ) -> None :
156
- if isinstance (request ._pyfuncitem , DoctestItem ) and shutil .which ("tmux" ):
157
- doctest_namespace ["server" ] = request .getfixturevalue ("server" )
158
- session : "Session" = request .getfixturevalue ("session" )
159
- doctest_namespace ["session" ] = session
160
- doctest_namespace ["window" ] = session .attached_window
161
- doctest_namespace ["pane" ] = session .attached_pane
0 commit comments