Repository: tmux-python/libtmux (language: python)

Issue:
Tests for pytest plugin



Discussion / hints:

Fix patch:
diff --git a/CHANGES b/CHANGES
index 0b0c65c3a..2eacc56b6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 62571f546..ec9aaf09f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,1 +1,3 @@
 from libtmux.conftest import *  # NOQA: F4
+
+pytest_plugins = ["pytester"]
diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py
new file mode 100644
index 000000000..b165806e3
--- /dev/null
+++ b/tests/test_pytest_plugin.py
@@ -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)