davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.78k stars 508 forks source link

Add support for async pytest fixtures #1979

Open stinovlas opened 8 months ago

stinovlas commented 8 months ago

Hi! I was trying to get jedi (actually python-lsp-server) working with pytest and I bumped into the fact that jedi apparently doesn't recognize asynchronous pytest fixtures. The autocomplete works on synchronous fixtures (both from pytest itself and from my conftest.py, but the asynchronous fixtures are not picked up. Showcase:

import asyncio
import pytest

@pytest.fixture
def anyio_backend():
    return "asyncio"

@pytest.fixture
async def async_fixture(anyio_backend):
    return []

@pytest.fixture
def sync_fixture():
    return []

The sync_fixture is picked up by jedi and hinted properly. The async_fixture seems to be completely ignored.

I didn't have time yet to delve into jedi code and research how difficult such support would be, but I believe it shouldn't be enormous amount of work, considering we already have working detection for synchronous fixtures.