A pytest plugin for end-to-end testing of language servers
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_lsp-1.0.0.tar.gz.
File metadata
- Download URL: pytest_lsp-1.0.0.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba8c95b2d975a360249ffa5768e1e6f44d87d10ef7754070d3b321102724a2f1
|
|
| MD5 |
5f92dd41f829e8125f30b0c0f75a6084
|
|
| BLAKE2b-256 |
198abc978a7d1467489a3abcdcd16c98b6846a50fadc67a1936cf3d19bf948f0
|
Provenance
The following attestation bundles were made for pytest_lsp-1.0.0.tar.gz:
Publisher:
pytest-lsp-release.yml on swyddfa/lsp-devtools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_lsp-1.0.0.tar.gz -
Subject digest:
ba8c95b2d975a360249ffa5768e1e6f44d87d10ef7754070d3b321102724a2f1 - Sigstore transparency entry: 640268819
- Sigstore integration time:
-
Permalink:
swyddfa/lsp-devtools@929f38e95bdf2770db56d3821891be094f998cb1 -
Branch / Tag:
refs/heads/release - Owner: https://github.com/swyddfa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pytest-lsp-release.yml@929f38e95bdf2770db56d3821891be094f998cb1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_lsp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_lsp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36d002eda8d9bcd3ff9a5b33c382dd29dfd054ad9e475ad31d3aac53fdbf516b
|
|
| MD5 |
4ab227e8fdbe0ab454e88013d514e17d
|
|
| BLAKE2b-256 |
dd0fb8564e8bbec03a6efe76fe450f0d328e8df96c603340055fef7e4428208b
|
Provenance
The following attestation bundles were made for pytest_lsp-1.0.0-py3-none-any.whl:
Publisher:
pytest-lsp-release.yml on swyddfa/lsp-devtools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_lsp-1.0.0-py3-none-any.whl -
Subject digest:
36d002eda8d9bcd3ff9a5b33c382dd29dfd054ad9e475ad31d3aac53fdbf516b - Sigstore transparency entry: 640268822
- Sigstore integration time:
-
Permalink:
swyddfa/lsp-devtools@929f38e95bdf2770db56d3821891be094f998cb1 -
Branch / Tag:
refs/heads/release - Owner: https://github.com/swyddfa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pytest-lsp-release.yml@929f38e95bdf2770db56d3821891be094f998cb1 -
Trigger Event:
push
-
Statement type: