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

params on Fixtures are silently hidden when the Fixture is shadowed but used #11337

Open
jgersti opened this issue Aug 22, 2023 · 2 comments
Open
Labels
topic: fixtures anything involving fixtures directly or indirectly topic: parametrize related to @pytest.mark.parametrize

Comments

@jgersti
Copy link

jgersti commented Aug 22, 2023

Issue

params on fixtures that are shadowed but used are silently dropped.

Example

@pytest.fixture
def b(a): return a

@pytest.fixture(name="a", params=("inner", "near"))
def a_inner(request):
    return f"#{request.param}"

@pytest.fixture(name="a", params=("outer", "far"))
def a_outer(request, a, b):
    return f"+{request.param} {a} {b}"

def test_nested(a):
    print(a)

this result in something like

> pytest -s -q -vvv
::test_nested[outer]
+outer #outer #outer
PASSED
::test_nested[far]
+far #far #far
PASSED

I expect to atleast get a warning that the params on the inner fixture are overwritten by the paramson the outer one

Note I:

I actually hoped to get all four cases (outer-inner, outer-near, far-inner, far-near), but i guess that wont happen anytime (see Note III)

Note II:

The fixture b is only included to demonstrate that the inner fixture is/can be accessed when necessary.
Increasing the scope on the inner fixture does not change anything.

Note III:

I am aware that the current behaviour (ignoring the params on the inner fixture) is the current way to make indirect parameters in pytest.mark.parametrize work, because pytest.mark.parametrize in effect just shadows fixtures.

Sytem Info:

pytest-7.4.0
win10 & python 3.11

@RonnyPfannschmidt
Copy link
Member

Params are by name ,not by fixture definition

@RonnyPfannschmidt RonnyPfannschmidt added topic: parametrize related to @pytest.mark.parametrize topic: fixtures anything involving fixtures directly or indirectly labels Aug 22, 2023
@jgersti
Copy link
Author

jgersti commented Aug 25, 2023

Params are by name ,not by fixture definition

I was aware, this is what i meant by shadowing and why i asked for a warning when there are multiple params for a name detected.

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
Projects
None yet
Development

No branches or pull requests

2 participants