Skip to main content

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


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-1.0.0b2.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

pytest_lsp-1.0.0b2-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_lsp-1.0.0b2.tar.gz.

File metadata

  • Download URL: pytest_lsp-1.0.0b2.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_lsp-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 459f62d578d700b63c4ea0b500b5a621461eb2c60d0fd941c3583b0d7930a1ea
MD5 49a3b8ade93fca5bdbdfc28dfffac1fb
BLAKE2b-256 a9471207bf70218c9cbb6e8a184a1957f699c35d9bf8b43dfa2be5885d35c283

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_lsp-1.0.0b2.tar.gz:

Publisher: pytest-lsp-release.yml on swyddfa/lsp-devtools

Attestations:

File details

Details for the file pytest_lsp-1.0.0b2-py3-none-any.whl.

File metadata

  • Download URL: pytest_lsp-1.0.0b2-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_lsp-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 d989c69e134ac66e297f0e0eae5edb13470059d7028e50fb06c01674b067fc14
MD5 e2a3d8cc7b9844b4360aead15e0bde01
BLAKE2b-256 c1cc2f46f5a3db66e50e813cba64da0fed2c517c28b80877585461534c953f22

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_lsp-1.0.0b2-py3-none-any.whl:

Publisher: pytest-lsp-release.yml on swyddfa/lsp-devtools

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page