Skip to content

Commit 1806207

Browse files
authored
Consolidate conftest.py to root-level (#440)
- https://docs.pytest.org/en/stable/deprecations.html#pytest-plugins-in-non-top-level-conftest-files - Less conftest.py files - We can now run py.test for `README.md` without needing to proxy through `docs/index.md`
2 parents bd315dd + 5e0fa62 commit 1806207

File tree

5 files changed

+53
-49
lines changed

5 files changed

+53
-49
lines changed

CHANGES

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ $ pip install --user --upgrade --pre libtmux
1717
### Tests / docs
1818

1919
- Examples for pytest plugin (#439)
20+
- Move conftest.py to root level (#440)
21+
22+
- https://docs.pytest.org/en/stable/deprecations.html#pytest-plugins-in-non-top-level-conftest-files
23+
- Less conftest.py files
24+
- We can now run py.test for `README.md` without needing to proxy through
25+
`docs/index.md`
26+
2027

2128
## libtmux 0.15.2 (2022-09-17)
2229

conftest.py

+46
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
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+
114
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")

docs/conftest.py

-1
This file was deleted.

src/libtmux/conftest.py

-45
This file was deleted.

tests/conftest.py

-3
This file was deleted.

0 commit comments

Comments
 (0)