Recall & Review
beginner
What does combining multiple @pytest.mark.parametrize decorators do?
It creates tests for every combination of the parameters from each decorator, running the test function multiple times with all possible pairs.
Click to reveal answer
beginner
How do you write two @pytest.mark.parametrize decorators to test combinations of 'x' and 'y'?
You write one @pytest.mark.parametrize for 'x' values and another for 'y' values above the test function. Pytest runs the test for every pair of 'x' and 'y'.
Click to reveal answer
intermediate
What is the order of execution when combining multiple parametrize decorators?
The outer decorator's parameters change slower, and the inner decorator's parameters change faster, creating a Cartesian product of all parameter values.
Click to reveal answer
beginner
Why is combining multiple parametrize decorators useful?
It helps test many input combinations easily without writing many test functions, improving test coverage and saving time.
Click to reveal answer
beginner
Show a simple example of combining two parametrize decorators in pytest.
import pytest
@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', [3, 4])
def test_sum(x, y):
assert (x + y) in [4, 5, 6]Click to reveal answer
What happens when you combine two @pytest.mark.parametrize decorators on a test function?
✗ Incorrect
Combining multiple parametrize decorators causes pytest to run the test for every possible combination of the parameters.
If you have @pytest.mark.parametrize('a', [1, 2]) and @pytest.mark.parametrize('b', [3, 4]), how many test cases will run?
✗ Incorrect
The test runs for all combinations: (1,3), (1,4), (2,3), (2,4) which is 4 tests.
Which of these is the correct way to combine two parametrize decorators?
✗ Incorrect
Stacking multiple @pytest.mark.parametrize decorators is the correct way to combine parameters for all combinations.
What is the benefit of combining multiple parametrize decorators instead of one with tuples?
✗ Incorrect
Multiple parametrize decorators create the Cartesian product of parameters automatically, saving manual tuple listing.
In combined parametrize decorators, which parameter changes faster during test runs?
✗ Incorrect
The inner decorator's parameters change faster, cycling through all values for each outer parameter.
Explain how combining multiple @pytest.mark.parametrize decorators affects test execution.
Think about how nested loops work.
You got /4 concepts.
Describe a practical scenario where combining multiple parametrize decorators is helpful.
Imagine testing a function with two inputs.
You got /4 concepts.