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_lsp
from lsprotocol.types import (
CompletionParams,
InitializeParams,
Position,
TextDocumentIdentifier,
)
from pytest_lsp import (
ClientServerConfig,
LanguageClient,
client_capabilities,
)
@pytest_lsp.fixture(
config=ClientServerConfig(
server_command=[sys.executable, "-m", "esbonio"],
),
)
async def client(lsp_client: LanguageClient):
# Setup
response = await lsp_client.initialize_session(
InitializeParams(
capabilities=client_capabilities("visual-studio-code"),
root_uri="file:///path/to/test/project/root/",
)
)
yield
# Teardown
await lsp_client.shutdown_session()
async def test_completion(client: LanguageClient):
result = await client.text_document_completion_async(
params=CompletionParams(
position=Position(line=5, character=23),
text_document=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
pytest_lsp-0.4.3.tar.gz
(26.2 kB
view details)
Built Distribution
File details
Details for the file pytest_lsp-0.4.3.tar.gz
.
File metadata
- Download URL: pytest_lsp-0.4.3.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 343f6bda2faa320ed5fcb77c9420d2703ce565d1d144fe827e3198a7dc29911c |
|
MD5 | 4e841b7acf58e2cfe107b9a599da30eb |
|
BLAKE2b-256 | 5e180eef60a41a0cf3c0d3b70d5d16e1d88ac1dbc7674241e4774223e6c9577c |
File details
Details for the file pytest_lsp-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: pytest_lsp-0.4.3-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0263a7f7be1410fedcdb437dbd011daaf04ee37651e90ae95d8d2e2fec54565c |
|
MD5 | f938365d023c04ecd7e386bc77b265aa |
|
BLAKE2b-256 | db92c4ad6b4a9a1bdbc22b847919391643e31571bdedfd76c67a09aed61bbc97 |