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

passing functions to indirect parametrization instead of string #8146

Open
Vert53 opened this issue Dec 15, 2020 · 3 comments
Open

passing functions to indirect parametrization instead of string #8146

Vert53 opened this issue Dec 15, 2020 · 3 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly topic: parametrize related to @pytest.mark.parametrize type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@Vert53
Copy link

Vert53 commented Dec 15, 2020

What's the problem this feature will solve?

Currently when parametrizing a test indirectly through fixtures, the name of the fixture that the parameters will be passed to is specified as a string. For example:

@pytest.mark.parametrize(
    "my_fixture",
    [
        ("param", 2),
    ],
    indirect=True)
class TestFoo:
    pass

This approach is problematic because IDE's can't find usages of fixtures when these are passed as strings.
Also IDE's can't notice if the fixture's name is passed incorrectly.

Describe the solution you'd like

I propose to allow the parametrize method to receive function objects who's name can be retrieved internally in parametrize with the .name attribute of functions. Example:

@pytest.mark.parametrize(
    my_fixture,  # this time the function itself is passed
    [
        ("param", 2),
    ],
    indirect=True)
class TestFoo:
    pass

Waiting for feedback so I could perhaps implement this feature.

Thanks,
Vert

@RonnyPfannschmidt
Copy link
Member

currently fixture declarations are not symbolic and location-bound, as such its at least a breaking change, if not a major refactoring to properly introduce this

that being said, i'd like the fixture system to move to that direction, its just not clear to what changes/breakages are required to go there

@Vert53
Copy link
Author

Vert53 commented Dec 15, 2020

I am not fully aware of all the details but my understanding is that if my fixture is in a different file (say conftest.py) I can import the fixture and then pass it like in my last comment. This is mostly syntactic and good for static code checks and code navigation.
Shouldn't break the current method of passing strings.

@RonnyPfannschmidt
Copy link
Member

Importing fixtures means there are multiple definitions for the fixture at each import site, this creates trouble for scopes

@Zac-HD Zac-HD added topic: fixtures anything involving fixtures directly or indirectly topic: parametrize related to @pytest.mark.parametrize type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly topic: parametrize related to @pytest.mark.parametrize type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

3 participants