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

PyPIPyPI - DownloadsLicense: MIT

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.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_lsp-1.0.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_lsp-1.0.1.tar.gz.

File metadata

  • Download URL: pytest_lsp-1.0.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytest_lsp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cd9950fec2991e65364430dd419daeedf546928788f457e1106d5b751aea0be8
MD5 cfb03b14953db82bd84415228cf07d2e
BLAKE2b-256 c3b66cf89ad14813dd318d8a415e4d01809f89a6bf4649bf12df9934977329e7

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_lsp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_lsp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytest_lsp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a44390556253e384a1921cfc2eb9aad1c315e08576629e52942c71d35b95596
MD5 49c8464f498f0902c1821e6e7f0fb81a
BLAKE2b-256 cb0ee7dfc7fc80921004ea5989ef8d8d44762323f46dfd9e1440184483387242

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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