Recall & Review
beginner
What is a parametrized fixture in pytest?
A parametrized fixture is a fixture that runs multiple times with different input values, allowing tests to reuse setup code with various data.
Click to reveal answer
beginner
How do you define a parametrized fixture in pytest?
Use the @pytest.fixture decorator with the 'params' argument listing values. pytest runs the fixture once for each value.
Click to reveal answer
beginner
Example: What does this fixture do?
@pytest.fixture(params=[1, 2, 3])
def number(request):
return request.paramIt creates a fixture named 'number' that will provide values 1, 2, and 3 to tests, running each test three times with these values.
Click to reveal answer
intermediate
Why use parametrized fixtures instead of multiple test functions?
Parametrized fixtures reduce code duplication and keep tests clean by reusing setup logic with different inputs automatically.
Click to reveal answer
beginner
How can you access the current parameter value inside a parametrized fixture?
Use 'request.param' inside the fixture function to get the current parameter value.
Click to reveal answer
What does the 'params' argument in @pytest.fixture do?
✗ Incorrect
The 'params' argument tells pytest to run the fixture once for each value provided.
How do you get the current parameter value inside a parametrized fixture?
✗ Incorrect
Inside the fixture, 'request.param' holds the current parameter value.
If a fixture is parametrized with 3 values, how many times will a test using it run?
✗ Incorrect
The test runs once for each parameter value, so 3 times.
Which decorator is used to create a parametrized fixture?
✗ Incorrect
Parametrized fixtures use @pytest.fixture with the 'params' argument.
What is a benefit of parametrized fixtures?
✗ Incorrect
Parametrized fixtures help reuse setup code and avoid repeating similar tests.
Explain how to create and use a parametrized fixture in pytest.
Think about how pytest runs tests multiple times with different data.
You got /3 concepts.
Describe the advantages of using parametrized fixtures over writing multiple test functions.
Consider how setup code can be reused.
You got /3 concepts.