Skip to content

Commit 32ade43

Browse files
authored
tests(conftest): Add pytester plugin (#423)
2 parents 49b9d6c + 124cb52 commit 32ade43

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ $ pip install --user --upgrade --pre libtmux
1212

1313
- _Insert changes/features/fixes for next release here_
1414

15+
### Tests
16+
17+
- pytest plugin: Initial tests (for testing the plugin itself, #423)
18+
1519
### Packaging
1620

1721
- pyproject.toml: Note pytest framework in trove classifiers

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from libtmux.conftest import * # NOQA: F4
2+
3+
pytest_plugins = ["pytester"]

tests/test_pytest_plugin.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import textwrap
2+
3+
import pytest
4+
5+
import _pytest.pytester
6+
7+
8+
def test_plugin(
9+
pytester: _pytest.pytester.Pytester,
10+
monkeypatch: pytest.MonkeyPatch,
11+
) -> None:
12+
# Initialize variables
13+
pytester.plugins = ["pytest_plugin"]
14+
pytester.makefile(
15+
".ini",
16+
pytest=textwrap.dedent(
17+
"""
18+
[pytest]
19+
addopts=-vv
20+
""".strip()
21+
),
22+
)
23+
pytester.makeconftest(
24+
textwrap.dedent(
25+
r"""
26+
import pathlib
27+
import pytest
28+
29+
@pytest.fixture(autouse=True)
30+
def setup(
31+
request: pytest.FixtureRequest,
32+
) -> None:
33+
pass
34+
"""
35+
)
36+
)
37+
tests_path = pytester.path / "tests"
38+
files = {
39+
"example.py": textwrap.dedent(
40+
"""
41+
import pathlib
42+
43+
def test_repo_git_remote_checkout(
44+
session,
45+
) -> None:
46+
assert session.name is not None
47+
48+
assert session._session_id == "$1"
49+
50+
new_window = session.new_window(attach=False, window_name="my window name")
51+
assert new_window.name == "my window name"
52+
"""
53+
)
54+
}
55+
first_test_key = list(files.keys())[0]
56+
first_test_filename = str(tests_path / first_test_key)
57+
58+
# Setup: Files
59+
tests_path.mkdir()
60+
for file_name, text in files.items():
61+
test_file = tests_path / file_name
62+
test_file.write_text(
63+
text,
64+
encoding="utf-8",
65+
)
66+
67+
# Test
68+
result = pytester.runpytest(str(first_test_filename))
69+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)