microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 769 forks source link

No type or autocomplete present in test function despite pytest fixture having type hint on mouseover #5702

Open Evan0000000000 opened 5 months ago

Evan0000000000 commented 5 months ago

Discussed in #5510 , I don't seem to have the ability to reopen that ticket so I opted to create a new one. As mentioned there it seems as if this should be working as of #4590 but I'm seeing different behavior:

image

I'm unclear if something about pytest-mock might be causing this not to work correctly or if #4590 doesn't actually apply to this situation, or if it's something else, but I'd like to come to a conclusion one way or another.

Environment data

Code Snippet

import pytest
from pytest_mock import mocker

@pytest.fixture
def myfixture(mocker):

    mocker.patch() # Should see type and autocomplete here

Expected behavior

Hovering over the fixture within the test case signature and the test case code should type it correctly and autocomplete should work

Actual behavior

Hovering over the fixture in the test case signature types it correctly, but not in the test case code. Autocomplete does not work

Logs

The paths involved with the trace logs reveal some information about my employer and aspects of the code I work on I'd need to spend some time redacting. Can provide these but I'd rather not take the time if it's not required for this issue.

bschnurr commented 5 months ago

Thanks for the issue.

For the best experience I recommend adding type annotation mocker: MockerFixture like in the pytest docs here https://pypi.org/project/pytest-mock/3.7.0/

from pytest_mock import MockerFixture

def test_foo(mocker: MockerFixture) -> None:
    ...

there might be a issue related to fixtures that return a generator that we fail to provide autocompletions for.

image

heejaechang commented 5 months ago

not sure on top of my head why this could be happening. we might be failed to create types to inject for fixture completion. or failed to inject correct import statements for fixtures.

starting point to investigate should be here - https://github.com/microsoft/pyrx/blob/main/packages/pylance-internal/src/pytest/pyTestDocumentTransformer.ts#L103

bschnurr commented 5 months ago

related to https://github.com/microsoft/pylance-release/issues/5718

fixture using yield

Akopov4 commented 2 weeks ago

Hello, is there any movement in this investigation?