Challenge - 5 Problems
Single Parameter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest single parameter test
What is the output of this pytest test when run?
PyTest
import pytest @pytest.mark.parametrize('num', [1, 2, 3]) def test_is_positive(num): assert num > 0 if __name__ == '__main__': pytest.main(['-v'])
Attempts:
2 left
💡 Hint
Each parameter value runs the test once.
✗ Incorrect
The test runs three times with num=1, 2, and 3. All are positive, so all pass.
❓ assertion
intermediate2:00remaining
Assertion failure with single parameter
Given this test, which input causes the assertion to fail?
PyTest
import pytest @pytest.mark.parametrize('value', [1, 2, -1]) def test_positive(value): assert value > 0
Attempts:
2 left
💡 Hint
Check which values are not greater than zero.
✗ Incorrect
Only -1 is less than or equal to zero, so the assertion fails for value = -1.
❓ locator
advanced2:00remaining
Best locator for pytest parameter name
Which locator correctly identifies the parameter name in this pytest decorator?
PyTest
@pytest.mark.parametrize('input_value', [10, 20]) def test_func(input_value): assert input_value > 0
Attempts:
2 left
💡 Hint
The parameter name is inside the string in parametrize decorator.
✗ Incorrect
The parameter name is the string inside the parametrize decorator. Regex can extract it reliably.
🔧 Debug
advanced2:00remaining
Debugging failing pytest parameter test
Why does this pytest test fail?
PyTest
import pytest @pytest.mark.parametrize('x', [1, 2, 3]) def test_double(x): assert x * 2 == '2', 'Expected double to be string "2"'
Attempts:
2 left
💡 Hint
Check the types compared in the assertion.
✗ Incorrect
The test compares an integer (x*2) to a string '2', causing assertion failure but no TypeError.
❓ framework
expert2:00remaining
Effect of single parameter on test count in pytest
If a pytest test uses @pytest.mark.parametrize with a single parameter having 4 values, how many test cases are executed?
PyTest
import pytest @pytest.mark.parametrize('val', [10, 20, 30, 40]) def test_val(val): assert val > 0
Attempts:
2 left
💡 Hint
Each parameter value runs the test once.
✗ Incorrect
Each value in the parameter list runs the test once, so 4 values mean 4 test cases.