0
0
PyTesttesting~20 mins

Combining multiple parametrize decorators in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parametrize Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of combined parametrize decorators in pytest
What is the total number of test cases executed by pytest for the following test function?
PyTest
import pytest

@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', [3, 4, 5])
def test_sum(x, y):
    assert (x + y) > 0
A3
B6
C5
D2
Attempts:
2 left
💡 Hint
Remember that multiple parametrize decorators multiply the number of test cases.
assertion
intermediate
2:00remaining
Assertion behavior with combined parametrize decorators
Given the following test, which assertion will fail during pytest execution?
PyTest
import pytest

@pytest.mark.parametrize('a', [0, 1])
@pytest.mark.parametrize('b', [2, 3])
def test_multiply(a, b):
    assert (a * b) != 0
Aa=1, b=3
Ba=0, b=2
Ca=1, b=2
Da=0, b=3
Attempts:
2 left
💡 Hint
Check when the product of a and b equals zero.
🔧 Debug
advanced
2:00remaining
Identify the error in combined parametrize usage
What error will pytest raise when running this test code?
PyTest
import pytest

@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('x', [3, 4])
def test_values(x):
    assert x > 0
AValueError: conflicting parameter names
BTypeError: multiple values for argument 'x'
CSyntaxError: duplicate decorator parameter
Dpytest collects 4 tests and runs successfully
Attempts:
2 left
💡 Hint
Consider how pytest handles multiple parametrize decorators with the same argument name.
🧠 Conceptual
advanced
2:00remaining
Order of parameter combinations with multiple parametrize decorators
In pytest, when combining multiple parametrize decorators, which statement about the order of test case generation is true?
AThe outer decorator's parameters vary faster than the inner decorator's parameters.
BOnly the first decorator's parameters are used; others are ignored.
CThe inner decorator's parameters vary faster than the outer decorator's parameters.
DParameters vary randomly regardless of decorator order.
Attempts:
2 left
💡 Hint
Think about nested loops and which loop runs inside the other.
framework
expert
3:00remaining
Combining parametrize with indirect fixture in pytest
Given the following pytest code, how many test cases will be executed?
PyTest
import pytest

@pytest.fixture

def data(request):
    return request.param * 2

@pytest.mark.parametrize('data', [1, 2], indirect=True)
@pytest.mark.parametrize('flag', [True, False])
def test_indirect(data, flag):
    assert isinstance(data, int) and isinstance(flag, bool)
A1
B2
C3
D4
Attempts:
2 left
💡 Hint
Consider how indirect parametrize and multiple decorators combine.