0
0
PyTesttesting~5 mins

Combining multiple parametrize decorators in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe test runs once with the first parameters only.
BThe test fails to run due to conflict.
CThe test runs only with the parameters from the last decorator.
DThe test runs for every combination of parameters from both decorators.
If you have @pytest.mark.parametrize('a', [1, 2]) and @pytest.mark.parametrize('b', [3, 4]), how many test cases will run?
A2
B4
C3
D1
Which of these is the correct way to combine two parametrize decorators?
A@pytest.mark.parametrize('x', [1,2]) @pytest.mark.parametrize('y', [3,4])
B@pytest.mark.parametrize('x,y', [(1,3), (2,4)])
C@pytest.mark.parametrize('x,y', [1,2,3,4])
D@pytest.mark.parametrize('x') @pytest.mark.parametrize('y')
What is the benefit of combining multiple parametrize decorators instead of one with tuples?
ANo benefit, both are the same.
BCombining decorators runs fewer tests.
CCombining decorators creates all combinations automatically.
DCombining decorators is slower.
In combined parametrize decorators, which parameter changes faster during test runs?
AThe parameter in the inner decorator.
BThe parameter in the outer decorator.
CBoth change at the same speed.
DParameters do not change.
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.