Skip to main content

A blazingly fast Language Server Protocol implementation for pytest

Project description

pytest-language-server 🔥

Shamelessly vibed into existence 🤖✨

This entire LSP implementation was built from scratch in a single AI-assisted coding session. No template. No boilerplate. Just pure vibes and Rust. That's right - a complete, working Language Server Protocol implementation for pytest, vibed into reality through the power of modern AI tooling. Even this message about vibing was vibed into existence.

A blazingly fast Language Server Protocol (LSP) implementation for pytest, built with Rust.

Features

🎯 Go to Definition

Jump directly to fixture definitions from anywhere they're used:

  • Local fixtures in the same file
  • Fixtures in conftest.py files
  • Third-party fixtures from pytest plugins (pytest-mock, pytest-asyncio, etc.)
  • Respects pytest's fixture shadowing/priority rules

🔍 Find References

Find all usages of a fixture across your entire test suite:

  • Works from fixture definitions or usage sites
  • Character-position aware (distinguishes between fixture name and parameters)
  • Shows references in all test files

📚 Hover Documentation

View fixture information on hover:

  • Fixture signature
  • Source file location
  • Docstring (with proper formatting and dedenting)
  • Markdown support in docstrings

⚡️ Performance

Built with Rust for maximum performance:

  • Fast workspace scanning with concurrent file processing
  • Efficient AST parsing using rustpython-parser
  • Lock-free data structures with DashMap
  • Minimal memory footprint

Installation

From PyPI (Recommended)

Using uv (recommended):

uv tool install pytest-language-server

Or with pip:

pip install pytest-language-server

From Crates.io

cargo install pytest-language-server

From Source

git clone https://github.com/bellini666/pytest-language-server
cd pytest-language-server
cargo build --release

The binary will be at target/release/pytest-language-server.

Setup

Neovim (with nvim-lspconfig)

require'lspconfig'.pytest_lsp.setup{
  cmd = { "pytest-language-server" },
  filetypes = { "python" },
  root_dir = function(fname)
    return require'lspconfig'.util.root_pattern('pyproject.toml', 'setup.py', 'setup.cfg', 'pytest.ini')(fname)
  end,
}

VS Code

Install the extension from the marketplace (coming soon) or configure manually:

{
  "pytest-language-server.enable": true,
  "pytest-language-server.path": "pytest-language-server"
}

Other Editors

Any editor with LSP support can use pytest-language-server. Configure it to run the pytest-language-server command.

Configuration

Logging

Control log verbosity with the RUST_LOG environment variable:

# Minimal logging (default)
RUST_LOG=warn pytest-language-server

# Info level
RUST_LOG=info pytest-language-server

# Debug level (verbose)
RUST_LOG=debug pytest-language-server

# Trace level (very verbose)
RUST_LOG=trace pytest-language-server

Logs are written to stderr, so they won't interfere with LSP communication.

Virtual Environment Detection

The server automatically detects your Python virtual environment:

  1. Checks for .venv/, venv/, or env/ in your project root
  2. Falls back to $VIRTUAL_ENV environment variable
  3. Scans third-party pytest plugins for fixtures

Supported Fixture Patterns

Decorator Style

@pytest.fixture
def my_fixture():
    """Fixture docstring."""
    return 42

Assignment Style (pytest-mock)

mocker = pytest.fixture()(_mocker)

Async Fixtures

@pytest.fixture
async def async_fixture():
    return await some_async_operation()

Fixture Dependencies

@pytest.fixture
def fixture_a():
    return "a"

@pytest.fixture
def fixture_b(fixture_a):  # Go to definition works on fixture_a
    return fixture_a + "b"

Fixture Priority Rules

pytest-language-server correctly implements pytest's fixture shadowing rules:

  1. Same file: Fixtures defined in the same file have highest priority
  2. Closest conftest.py: Searches parent directories for conftest.py files
  3. Virtual environment: Third-party plugin fixtures

Supported Third-Party Fixtures

Automatically discovers fixtures from popular pytest plugins:

  • pytest-mock: mocker, class_mocker
  • pytest-asyncio: event_loop
  • pytest-django: Database fixtures
  • pytest-cov: Coverage fixtures
  • And any other pytest plugin in your environment

Architecture

  • Language: Rust 🦀
  • LSP Framework: tower-lsp
  • Parser: rustpython-parser
  • Concurrency: tokio async runtime
  • Data Structures: DashMap for lock-free concurrent access

Development

Prerequisites

  • Rust 1.70+ (2021 edition)
  • Python 3.8+ (for testing)

Building

cargo build --release

Running Tests

cargo test

Logging During Development

RUST_LOG=debug cargo run

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Acknowledgments

Built with:

Special thanks to the pytest team for creating such an amazing testing framework.


Made with ❤️ and Rust. Shamelessly vibed into existence. Blazingly fast. 🔥

When you need a pytest LSP and the vibes are just right.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pytest_language_server-0.1.0-py3-none-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file pytest_language_server-0.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytest_language_server-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 77f1960e526e60511c5d776fd5db512530f00f26811e5cdf3119a6766f9c4dfc
MD5 63a181bab06db107ffd766477e96698d
BLAKE2b-256 9edab0d6c0d47c7399a3d212b8e796a49c25a14e6cbe5c311ac6b063b69177c3

See more details on using hashes here.

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