pytest-dev / pytest-dev/pytest

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

Open
#11,337 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures topic: parametrize
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied nested-fixture example with pytest 7.4.0, then trace how fixture shadowing and parameter collection handle the inner and outer fixtures. Done means the silently dropped inner params are surfaced with a clear warning while the existing indirect-parameter behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.