0
0
PyTesttesting~20 mins

Multiple parameters in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multiple Parameters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
A4 tests run, all pass
B2 tests run, all pass
C2 tests run, some fail
D4 tests run, some fail
Attempts:
2 left
💡 Hint
Remember how pytest combines multiple parametrize decorators.
assertion
intermediate
2: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
Aassert (a - b) % 2 == 0
Bassert (a + b) % 2 == 0
Cassert (a * b) % 2 == 1
Dassert (a * b) % 2 == 0
Attempts:
2 left
💡 Hint
Check which operation and condition ensures even product.
🔧 Debug
advanced
2: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
Apytest runs 4 tests, all pass
BTypeError: test_values() missing 1 required positional argument: 'z'
Cpytest runs 6 tests, all pass
DValueError: too many values to unpack
Attempts:
2 left
💡 Hint
Check how pytest combines multiple parametrize decorators with multiple arguments.
locator
advanced
2: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?
Atest_sum(x=2,y=3)
Btest_sum[2-3]
Ctest_sum_2_3
Dtest_sum(2,3)
Attempts:
2 left
💡 Hint
pytest uses a specific format for parameterized test IDs.
framework
expert
2: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
A8 tests
B2 tests
C4 tests
D16 tests
Attempts:
2 left
💡 Hint
Multiply the number of values in each parametrize considering grouping.