Challenge - 5 Problems
Multiple Parameters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest with multiple parameters
What will be the output when running this pytest code with multiple parameters?
PyTest
import pytest @pytest.mark.parametrize("x", [1, 2]) @pytest.mark.parametrize("y", [3, 4]) def test_sum(x, y): assert x + y > 3
Attempts:
2 left
💡 Hint
Remember how pytest combines multiple parametrize decorators.
✗ Incorrect
pytest runs the test for all combinations of parameters from multiple @pytest.mark.parametrize decorators, so 2 values for x and 2 for y produce 4 tests. All pass because all sums are greater than 3.
❓ assertion
intermediate2:00remaining
Correct assertion for multiple parameters
Which assertion correctly verifies that the product of parameters a and b is always even in this test?
PyTest
import pytest @pytest.mark.parametrize("a", [1, 2]) @pytest.mark.parametrize("b", [2, 3]) def test_product_even(a, b): # Choose the correct assertion below
Attempts:
2 left
💡 Hint
Check which operation and condition ensures even product.
✗ Incorrect
The product is even if divisible by 2, so (a * b) % 2 == 0 is the correct assertion. Other options check sum or difference or odd product.
🔧 Debug
advanced2:00remaining
Identify the error in multiple parameter test
What error will this pytest code raise when run?
PyTest
import pytest @pytest.mark.parametrize("x, y", [(1, 2), (3, 4)]) @pytest.mark.parametrize("z", [5, 6]) def test_values(x, y, z): assert x + y + z > 0
Attempts:
2 left
💡 Hint
Check how pytest combines multiple parametrize decorators with multiple arguments.
✗ Incorrect
pytest combines parameters by Cartesian product. The first parametrize provides 2 tuples (x,y), second provides 2 values for z, so 2*2=4 tests. But since x,y are grouped, and z separate, total tests are 4. All sums are positive, so all pass.
❓ locator
advanced2:00remaining
Best locator for multiple parameter test cases
In a test report, which locator best identifies a test case with parameters x=2 and y=3 in pytest?
Attempts:
2 left
💡 Hint
pytest uses a specific format for parameterized test IDs.
✗ Incorrect
pytest shows parameterized test IDs in the format test_name[param1-param2], so test_sum[2-3] is the correct locator. Others are not standard pytest locators.
❓ framework
expert2:00remaining
Understanding parameter combination in pytest
Given these decorators, how many total test cases will pytest generate?
PyTest
import pytest @pytest.mark.parametrize("a", [1, 2]) @pytest.mark.parametrize("b, c", [(3, 4), (5, 6)]) @pytest.mark.parametrize("d", [7]) def test_func(a, b, c, d): pass
Attempts:
2 left
💡 Hint
Multiply the number of values in each parametrize considering grouping.
✗ Incorrect
pytest combines parameters by Cartesian product. a has 2 values, (b,c) has 2 tuples, d has 1 value. Total tests = 2 * 2 * 1 = 4 tests. But pytest applies parametrize decorators bottom-up, so the total is 2 (a) * 2 (b,c) * 1 (d) = 4 tests.