Skip to content

Commit 78505a7

Browse files
committed
test: Move even more fixtures to use libtmux's
1 parent 91251e5 commit 78505a7

File tree

1 file changed

+2
-70
lines changed

1 file changed

+2
-70
lines changed

tmuxp/conftest.py

+2-70
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
import pytest
88

99
from _pytest.doctest import DoctestItem
10-
from _pytest.fixtures import SubRequest
1110

12-
from libtmux import exc
13-
from libtmux.server import Server
14-
from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer
11+
from libtmux.test import namer
1512
from tests.fixtures import utils as test_utils
1613

1714
if t.TYPE_CHECKING:
@@ -57,74 +54,9 @@ def socket_name(request) -> str:
5754
return "tmuxp_test%s" % next(namer)
5855

5956

60-
@pytest.fixture(scope="function")
61-
def server(
62-
request: SubRequest, monkeypatch: pytest.MonkeyPatch, socket_name: str
63-
) -> Server:
64-
tmux = Server(socket_name=socket_name)
65-
66-
def fin() -> None:
67-
tmux.kill_server()
68-
69-
request.addfinalizer(fin)
70-
71-
return tmux
72-
73-
74-
@pytest.fixture(scope="function")
75-
def session(server):
76-
session_name = "tmuxp"
77-
78-
if not server.has_session(session_name):
79-
server.cmd(
80-
"-f",
81-
"/dev/null", # use a blank config to reduce side effects
82-
"new-session",
83-
"-d", # detached
84-
"-s",
85-
session_name,
86-
"/bin/sh", # use /bin/sh as a shell to reduce side effects
87-
# normally, it'd be -c, but new-session is special
88-
)
89-
90-
# find current sessions prefixed with tmuxp
91-
old_test_sessions = [
92-
s.get("session_name")
93-
for s in server._sessions
94-
if s.get("session_name").startswith(TEST_SESSION_PREFIX)
95-
]
96-
97-
TEST_SESSION_NAME = get_test_session_name(server=server)
98-
99-
try:
100-
session = server.new_session(session_name=TEST_SESSION_NAME)
101-
except exc.LibTmuxException as e:
102-
raise e
103-
104-
"""
105-
Make sure that tmuxp can :ref:`test_builder_visually` and switches to
106-
the newly created session for that testcase.
107-
"""
108-
session_id = session.get("session_id")
109-
assert session_id is not None
110-
try:
111-
server.switch_client(target_session=session_id)
112-
except exc.LibTmuxException:
113-
# server.attach_session(session.get('session_id'))
114-
pass
115-
116-
for old_test_session in old_test_sessions:
117-
logger.debug("Old test test session %s found. Killing it." % old_test_session)
118-
server.kill_session(old_test_session)
119-
assert TEST_SESSION_NAME == session.get("session_name")
120-
assert TEST_SESSION_NAME != "tmuxp"
121-
122-
return session
123-
124-
12557
@pytest.fixture(autouse=True)
12658
def add_doctest_fixtures(
127-
request: SubRequest,
59+
request: pytest.FixtureRequest,
12860
doctest_namespace: t.Dict[str, t.Any],
12961
) -> None:
13062
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):

0 commit comments

Comments
 (0)