Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Summerduck opened this issue Aug 23, 2024 · 2 comments
Open

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

Summerduck opened this issue Aug 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Summerduck
Copy link

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

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 23, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Aug 23, 2024

Thanks for the issue.

Do you have this enabled?

Image

Because this works for me:

Image

@rchiodo
Copy link
Contributor

rchiodo commented Aug 23, 2024

Sorry misunderstood. It's not working in the test class, but it is in the test method.

@rchiodo rchiodo added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants