A pytest plugin for end-to-end testing of language servers
Project Links
Meta
Author: Alex Carney
Requires Python: >=3.10
Classifiers
Development Status
- 5 - Production/Stable
Framework
- Pytest
License
- OSI Approved :: MIT License
Programming Language
- Python
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
pytest-lsp: End-to-end testing of language servers with pytest
pytest-lsp is a pytest plugin for writing end-to-end tests for language servers.
It works by running the language server in a subprocess and communicating with it over stdio, just like a real language client.
This also means pytest-lsp can be used to test language servers written in any language - not just Python.
pytest-lsp relies on the pygls library for its language server protocol implementation.
See the documentation for details on getting started.
import sys
import pytest
import pytest_lsp
from lsprotocol import types
from pytest_lsp import (
ClientServerConfig,
LanguageClient,
client_capabilities,
)
@pytest_lsp.fixture(
scope="module",
config=ClientServerConfig(
server_command=[sys.executable, "-m", "esbonio"],
),
)
async def client(lsp_client: LanguageClient):
# Setup
response = await lsp_client.initialize_session(
types.InitializeParams(
capabilities=client_capabilities("visual-studio-code"),
workspace_folders=[
types.WorkspaceFolder(
uri="file:///path/to/test/project/root/", name="project"
),
],
)
)
yield
# Teardown
await lsp_client.shutdown_session()
@pytest.mark.asyncio(loop_scope="module")
async def test_completion(client: LanguageClient):
result = await client.text_document_completion_async(
params=types.CompletionParams(
position=types.Position(line=5, character=23),
text_document=types.TextDocumentIdentifier(
uri="file:///path/to/test/project/root/test_file.rst"
),
)
)
assert len(result.items) > 0
1.0.0
Oct 25, 2025
1.0.0b2
Nov 23, 2024
1.0.0b1
Sep 04, 2024
0.4.3
Aug 28, 2024
0.4.2
May 22, 2024
0.4.1
Feb 07, 2024
0.4.0
Nov 13, 2023
0.3.1
Oct 06, 2023
0.3.0
May 19, 2023
0.2.1
Jan 14, 2023
0.2.0
Jan 10, 2023
0.1.3
Oct 15, 2022
0.1.2
Jul 18, 2022
0.1.1
Jul 17, 2022
0.1.0
Jul 02, 2022
0.0.7
May 26, 2022
0.0.6
Apr 18, 2022
0.0.5
Apr 02, 2022
0.0.4
Mar 28, 2022
0.0.3
Mar 28, 2022
0.0.2
Mar 28, 2022
0.0.1
Mar 28, 2022