Meaning
A pytest fixture that provides parameterized values (10, 20, 30) to test functions that request it via request.param.
Primary Function
Supplies parameterized test inputs to test functions through the fixture's request.param mechanism.
Communicative Purpose
Communicates that the fixture supplies a set of parameter values for test parametrization.
Pattern
@pytest.fixture(params=[<values>])\ndef <fixture_name>(request): return request.param
Core Structure
@pytest.fixture(params=[<list of values>])\ndef <fixture_name>(request): return request.param
Função primária
Supplies parameterized test inputs to test functions through the fixture's request.param mechanism.
Propósito comunicativo
Communicates that the fixture supplies a set of parameter values for test parametrization.
Situações de gatilho
Used when writing parametrized tests where the same test logic should run with multiple input values and the fixture encapsulates the parameter set.
Contextos
Inside pytest test modules where test functions request the fixture named 'param_fixture'.
Padrão
@pytest.fixture(params=[<values>])\ndef <fixture_name>(request): return request.param
Estrutura central
@pytest.fixture(params=[<list of values>])\ndef <fixture_name>(request): return request.param
Slots de substituição
<fixture_name>, <list of values>
Colocados típicos
- @pytest.fixture
- request
- request.param
- @pytest.mark.parametrize
- test_
Substituições comuns
- Different param lists (e.g.
- [1
- 2
- 3]
- ['a'
- 'b'])
- different fixture names
- adding scope or autouse.
Erros comuns
Forgetting to return request.param, misplacing the params argument, confusing fixture params with @pytest.mark.parametrize arguments, using request.param incorrectly in setup.
Similar / contraste
Using @pytest.mark.parametrize directly on test functions vs. fixture-based parametrization; using a plain @pytest.fixture without params for fixed setup.
Interferências
Mixing fixture param usage with mark parametrization can cause unexpected duplicate test invocations.
Família do chunk
- pytest-fixture
Nuance
Allows varying fixture setup per test iteration while keeping the test function signature clean.
Efeito pragmático
Enables reusable test setup with multiple input configurations, reducing boilerplate.
Dica de memória
param_fixture
Nota
The params argument accepts any iterable; using scope='module' or 'function' controls fixture lifetime, and autouse=True applies the fixture automatically to all tests in its scope.
Upgrade path
Could evolve to using @pytest.mark.parametrize directly on test functions for simpler cases, or adding fixture scope/autouse for broader setup.
Log in to save chunks.