Skip to content

tests(conftest): Add pytester plugin #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ $ pip install --user --upgrade --pre libtmux

- _Insert changes/features/fixes for next release here_

### Tests

- pytest plugin: Initial tests (for testing the plugin itself, #423)

### Packaging

- pyproject.toml: Note pytest framework in trove classifiers
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from libtmux.conftest import * # NOQA: F4

pytest_plugins = ["pytester"]
69 changes: 69 additions & 0 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import textwrap

import pytest

import _pytest.pytester


def test_plugin(
pytester: _pytest.pytester.Pytester,
monkeypatch: pytest.MonkeyPatch,
) -> None:
# Initialize variables
pytester.plugins = ["pytest_plugin"]
pytester.makefile(
".ini",
pytest=textwrap.dedent(
"""
[pytest]
addopts=-vv
""".strip()
),
)
pytester.makeconftest(
textwrap.dedent(
r"""
import pathlib
import pytest

@pytest.fixture(autouse=True)
def setup(
request: pytest.FixtureRequest,
) -> None:
pass
"""
)
)
tests_path = pytester.path / "tests"
files = {
"example.py": textwrap.dedent(
"""
import pathlib

def test_repo_git_remote_checkout(
session,
) -> None:
assert session.name is not None

assert session._session_id == "$1"

new_window = session.new_window(attach=False, window_name="my window name")
assert new_window.name == "my window name"
"""
)
}
first_test_key = list(files.keys())[0]
first_test_filename = str(tests_path / first_test_key)

# Setup: Files
tests_path.mkdir()
for file_name, text in files.items():
test_file = tests_path / file_name
test_file.write_text(
text,
encoding="utf-8",
)

# Test
result = pytester.runpytest(str(first_test_filename))
result.assert_outcomes(passed=1)