Skip to content

"Go to Definition" not working for test functions inside classes #6292

Description

@summerduck

Environment data

  • Pylance version: v2024.8.101 (pre-release)
  • ProductName: macOS
  • ProductVersion: 14.2.1
  • BuildVersion: 23C71
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.12.5

Code Snippet

# File: pages/home_page.py
class HomePage:
    """
    Module description
    """
    def __init__(self) -> None:
        pass
    
    def params_navigation(self):
        """
        Method description
        """
        print("params_navigation")


# File: tests/test_file_tests.py
class TestClassTest:
    def test_without_method_definition(
        self,
        fixture_from_main,
        fixture_from_tests,
    ):
        fixture_from_main.params_navigation()
        fixture_from_tests.params_navigation()


def test_with_method_definition(
        fixture_from_main,      
        fixture_from_tests
    ):
        fixture_from_main.params_navigation()
        fixture_from_tests.params_navigation()

# File: tests/conftest.py
import pytest
from pages.home_page import HomePage


@pytest.fixture
def fixture_from_tests() -> HomePage:
    return HomePage()

# File: tests/conftest.py
import pytest
from pages.home_page import HomePage


@pytest.fixture
def fixture_from_main() -> HomePage:
    return HomePage()

# File: test_file_main.py
class TestClassTest:
    def test_without_method_definition(
        self,
        fixture_from_main,
    ):
        fixture_from_main.params_navigation()


def test_with_method_definition(fixture_from_main):
    fixture_from_main.params_navigation()

Note that the HomePage class is initialized by a fixture in the conftest.py file and passed to the test functions.

Repro Steps

  1. Navigate to the test_file_tests.py or test_file_main.py file.
  2. Attempt to use "Go to Definition" on the params_navigation method call inside and outside the test methods.
    Untitled Project V2

Expected behavior

The "Go to Definition" should navigate to the params_navigation method definition in home_page.py.
Screenshot 2024-08-23 at 7 01 07 PM

Actual behavior

No navigation occurs.
Screenshot 2024-08-23 at 6 59 11 PM

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingduplicateThis issue or pull request already existsrepro workspaceIssue has a retained repro workspace

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions