Skip to content

Pytest fixtures inside classes #2071

@jakubbortlik

Description

@jakubbortlik

Hi and thanks for the amazing software!

I'm using Jedi through python-lsp-server inside Neovim - this chain of tools makes me doubt whether this is the right place to ask about this, but hopefully it is.

And I'd like to ask about the possibility of supporting the resolution of Pytest fixtures when a fixture is defined inside a class.

The following example show the current behaviour where a fixture (fix) defined as a method inside a class is not recognized properly and the fix parameter in test_fix is incorrectly linked by Jedi to the function defined outside the class while Pytest will actually use the class method.

Would it be possible to fix this? Thanks!

import pytest


class Obj:
    attr = 1


class OtherObj:
    other_attr = 1


@pytest.fixture
def fix():
    return Obj()


class TestClass:
    @pytest.fixture
    def fix(self):
        return OtherObj()

    def test_fix(self, fix):
        fix.attr  # gets completed but should not, goToDefinition takes me to the function but should take me to the method
        fix.other_attr  # doesn't get completed but should

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions