0
0
PyTesttesting~10 mins

Why parametrize multiplies test coverage in PyTest - Test Your Understanding

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.

PyTest
import pytest

@pytest.mark.parametrize('input', [1])
def test_example(input):
    assert input > 0
Drag options to blanks, or click blank then click option'
A{1, 2}
B1, 2
C(1, 2)
D[1, 2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or braces instead of square brackets.
2fill in blank
medium

Complete the code to parametrize the test with two arguments: input and expected.

PyTest
import pytest

@pytest.mark.parametrize('[1]', [(1, 2), (3, 4)])
def test_sum(input, expected):
    assert input + 1 == expected
Drag options to blanks, or click blank then click option'
A'input expected'
B'input; expected'
C'input, expected'
D'input|expected'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or other separators instead of commas.
3fill in blank
hard

Fix the error in the parametrize decorator to correctly test multiple cases.

PyTest
import pytest

@pytest.mark.parametrize('num, expected', [1])
def test_double(num, expected):
    assert num * 2 == expected
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B[(1, 2), (2, 4), (3, 6)]
C[(1, 2), (2, 4), 3]
D[(1, 2), (2, 4), (3,)]
Attempts:
3 left
💡 Hint
Common Mistakes
Using single values instead of tuples.
Tuples with wrong number of elements.
4fill in blank
hard

Fill both blanks to parametrize a test with three parameters and three sets of values.

PyTest
import pytest

@pytest.mark.parametrize('[1]', [2])
def test_calc(a, b, c):
    assert a + b == c
Drag options to blanks, or click blank then click option'
A'a, b, c'
B'a b c'
C[(1, 2, 3), (4, 5, 9), (3, 3, 6)]
D[(1, 2), (4, 5), (3, 3)]
Attempts:
3 left
💡 Hint
Common Mistakes
Using space-separated parameter names.
Tuples with wrong number of elements.
5fill in blank
hard

Fill all three blanks to parametrize a test with two parameters and check if the sum is even.

PyTest
import pytest

@pytest.mark.parametrize('[1]', [2])
def test_even_sum(x, y):
    assert (x + y) [3] 0
Drag options to blanks, or click blank then click option'
A'x, y'
B[(1, 3), (2, 4), (5, 5)]
C% 2 ==
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter string format.
Incorrect assertion operator.