0
0
PyTesttesting~10 mins

Combining multiple parametrize decorators in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Anum
By
Cvalue
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name in the function than in the decorator.
2fill in blank
medium

Complete 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'
A'y'
B'num'
C'value'
D'z'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the function argument.
3fill in blank
hard

Fix 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'
A{3, 4}
B[3, 4]
C(3, 4)
D3, 4
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or braces instead of square brackets for the parameter list.
4fill in blank
hard

Fill 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'
A'x'
B'z'
C'y'
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parameter names or using incorrect names.
5fill in blank
hard

Fill 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'
A'x'
B'y'
C'z'
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names or missing one.