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
Release files for pytest-lsp 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_lsp-1.0.1.tar.gz | 29.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_lsp-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.2 kB
Release files / pytest_lsp-1.0.1.tar.gz
| Download URL | pytest_lsp-1.0.1.tar.gz |
|---|---|
| Size | 29.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd9950fec2991e65364430dd419daeedf546928788f457e1106d5b751aea0be8
|
|
BLAKE2b-256 checksum How to use checksums |
c3b66cf89ad14813dd318d8a415e4d01809f89a6bf4649bf12df9934977329e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 17, 2026.
Transparency logRelease files / pytest_lsp-1.0.1-py3-none-any.whl
| Download URL | pytest_lsp-1.0.1-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a44390556253e384a1921cfc2eb9aad1c315e08576629e52942c71d35b95596
|
|
BLAKE2b-256 checksum How to use checksums |
cb0ee7dfc7fc80921004ea5989ef8d8d44762323f46dfd9e1440184483387242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 17, 2026.
Transparency log