pytest-dev / pytest-dev/pytest
Override class-level fixture parametrization with method-level parametrization
Nobody has claimed this yet.
- 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?
Please see the below Python 3.8 code snippet. It involves:
- Fixture being indirectly parametrized
- Class parametrization: idea is this parameterization (
"b") applies to all tests - Method parameterization: idea is this parameterization (
"a") applies to just a particular method
- Class parametrization: idea is this parameterization (
from typing import Any
import pytest
@pytest.fixture
def some_fixture(request) -> Any:
assert "a" in request.param # Only passes for test_something
assert "b" in request.param # Always passes
# I apply to all test methods
@pytest.mark.parametrize("some_fixture", [{"b": "b"}], indirect=True)
class TestMultiParameterization:
# I apply to just this one test method
@pytest.mark.parametrize("some_fixture", [{"a": "a"}], indirect=True)
def test_something(self, some_fixture: Any) -> None:
pass
Running the test_something method via pytest==6.2.5, it will spit out the following error:
E ValueError: duplicate 'some_fixture'
Clearly, pytest rejects the duplicated parameterization.
Describe the solution you'd like
I would like if one could somehow "stitch together" parameterization from class-level parameterizations and method-level parameterizations.
The main benefit would be increased flexibility in parameterization of test fixtures. I am not sure how this could be accomplished in practice, though I do think it'd be useful functionality.
Alternative Solutions
I have not tried any alternate solutions.
Additional context
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 reproducing the class- and method-level fixture parametrization example with pytest 6.2.5 and confirm the duplicate 'some_fixture' error. Investigate pytest's parametrization handling, then define behavior where method-level parametrization overrides or combines with the class-level value while preserving the stated fixture assertions.
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
- 25/100