pytest-dev / pytest-dev/pytest
Using fixtures in pytest.mark.parametrize
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Originally reported by: Florian Rathgeber (BitBucket: frathgeber, GitHub: frathgeber)
I often have a use case like the following contrived example:
@pytest.fixture
def a():
return 'a'
@pytest.fixture
def b():
return 'b'
@pytest.mark.parametrize('arg', [a, b])
def test_foo(arg):
assert len(arg) == 1
This doesn't currently do what's intended i.e. arg inside the test function is not the fixture value but the fixture function.
I can work around it by introducing a "meta fixture", but that's rather ugly:
@pytest.fixture(params=['a', 'b'])
def arg(request, a, b):
return {'a': a, 'b': b}[request.param]
def test_foo(arg):
assert len(arg) == 1
It would be convenient if a syntax like in the first case was supported.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading pytest.mark.parametrize and the fixture-resolution behavior shown in the examples. The work is done when parametrization can supply fixture values rather than fixture functions, with tests covering the a and b example and the existing meta-fixture behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100