microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

Unimported pytest fixtures are recognized by hover #4900

Open debonte opened 1 year ago

debonte commented 1 year ago

Code Snippet

test_fixtures.py

from pytest import fixture

@fixture
def fixture_one():
    return 1

@fixture
def fixture_two():
    return 2

test_repro.py

from test_fixtures import fixture_one

def test_foo(fixture_two):
    pass

Repro Steps

  1. Add pytest to your venv
  2. Create files shown above
  3. Hover over fixture_two usage in test_repro.py

Expected behavior

Type of fixture_two is unknown since it is not imported. If you comment out the import of fixture_one you get the expected behavior: image

Actual behavior

Hover shows def fixture_two() -> Literal[2] image

rchiodo commented 11 months ago

I can repro this but this may be because fixture_two is allowed from pytest's point of view. Double checking.

rchiodo commented 11 months ago

No the test fails with the expected error. You have to actually import the fixture for the test to pass.