0
0
PyTesttesting~20 mins

Single parameter in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Single Parameter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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'])
ASyntaxError during test collection
B1 test passed, 2 failed
C3 tests passed
DAll tests skipped
Attempts:
2 left
💡 Hint
Each parameter value runs the test once.
assertion
intermediate
2: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
Avalue = 1
Bvalue = -1
Cvalue = 0
DAll values pass
Attempts:
2 left
💡 Hint
Check which values are not greater than zero.
locator
advanced
2: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
AJSON path for parameter list
BXPath locating function name 'test_func'
CCSS selector for function body
DRegex matching 'parametrize\('([^']+)'
Attempts:
2 left
💡 Hint
The parameter name is inside the string in parametrize decorator.
🔧 Debug
advanced
2: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"'
AComparing int to str causes assertion failure
BSyntaxError in parametrize decorator
CTypeError because x is not iterable
DTest passes without error
Attempts:
2 left
💡 Hint
Check the types compared in the assertion.
framework
expert
2: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
A4 test cases executed
B1 test case executed
C16 test cases executed
D0 test cases executed
Attempts:
2 left
💡 Hint
Each parameter value runs the test once.