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.0.tar.gz (28.5 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.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

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

Hashes for pytest_lsp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ba8c95b2d975a360249ffa5768e1e6f44d87d10ef7754070d3b321102724a2f1
MD5 5f92dd41f829e8125f30b0c0f75a6084
BLAKE2b-256 198abc978a7d1467489a3abcdcd16c98b6846a50fadc67a1936cf3d19bf948f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_lsp-1.0.0.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.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

Hashes for pytest_lsp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36d002eda8d9bcd3ff9a5b33c382dd29dfd054ad9e475ad31d3aac53fdbf516b
MD5 4ab227e8fdbe0ab454e88013d514e17d
BLAKE2b-256 dd0fb8564e8bbec03a6efe76fe450f0d328e8df96c603340055fef7e4428208b

See more details on using hashes here.

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

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