Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to parametrize the test with two values for x.
PyTest
@pytest.mark.parametrize('x', [1, 2]) def test_example([1]): assert x > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name in the function than in the decorator.
✗ Incorrect
The parameter name in the test function must match the name used in the parametrize decorator.
2fill in blank
mediumComplete the code to add a second parametrize decorator for y.
PyTest
@pytest.mark.parametrize('x', [1, 2]) @pytest.mark.parametrize([1], [3, 4]) def test_example(x, y): assert x + y > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the function argument.
✗ Incorrect
The second parametrize decorator must use the parameter name 'y' to match the function argument.
3fill in blank
hardFix the error in the combined parametrize decorators to test all combinations of x and y.
PyTest
@pytest.mark.parametrize('x', [1, 2]) @pytest.mark.parametrize('y', [1]) def test_example(x, y): assert x != y
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or braces instead of square brackets for the parameter list.
✗ Incorrect
The parametrize decorator expects a list of values for the parameter.
4fill in blank
hardFill both blanks to parametrize test with x and y and check their sum.
PyTest
@pytest.mark.parametrize([1], [1, 2]) @pytest.mark.parametrize([2], [3, 4]) def test_sum(x, y): assert x + y > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parameter names or using incorrect names.
✗ Incorrect
The first decorator should parametrize 'x' and the second 'y' to match the function parameters.
5fill in blank
hardFill all three blanks to parametrize x, y, and z and assert their product.
PyTest
@pytest.mark.parametrize([1], [1, 2]) @pytest.mark.parametrize([2], [3, 4]) @pytest.mark.parametrize([3], [5, 6]) def test_product(x, y, z): assert x * y * z > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names or missing one.
✗ Incorrect
Each parametrize decorator must match the corresponding function parameter name.