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.0.tar.gz
(24.1 kB
view hashes)
Built Distribution
pytest_lsp-0.4.0-py3-none-any.whl
(21.0 kB
view hashes)
Close
Hashes for pytest_lsp-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f626de6d792192ee9ba02a81ec156b452b1fe71fe7e039a87e7fa8d18222b922 |
|
MD5 | de5e3e7607c73bd31ea95d4f0369d9f8 |
|
BLAKE2b-256 | 2f90ec91acb65fb4cf9fc494b0a39438ff2de5fe22083350ed27f3ffb1a0def5 |