pytest-dev / pytest-dev/pytest

Warn if argument shadows fixture

Open
#10,512 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What's the problem this feature will solve?

Say I have the files:

$ cat test_t.py
import pytest

@pytest.mark.parametrize('closed', ['left', 'right', 'both', 'neither'])
def test_me(closed):
    assert closed in ['left', 'right', 'both', 'neither']

$ cat conftest.py
import pytest

@pytest.fixture(params=["left", "right", "both", "neither"])
def closed(request):
    return request.param
Describe the solution you'd like

Some warning that, in test_me, I have an argument whose name shadows that of a fixture

This came out of a PR in pandas https://github.com/pandas-dev/pandas/pull/49754#discussion_r1025656945

Alternative Solutions

I'm tempted to write my own tool to do this, just wanted to check it's not been done already. I tried searching "argument shadows fixture " and similar things in the issue tracker but didn't find anything.

Additional context

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

Reproduce the example using test_t.py and conftest.py, then trace how pytest resolves the test_me argument and the closed fixture. Define and test the warning behavior for an argument whose name matches a fixture, including the parametrized case shown in the issue.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.