0
0
PyTesttesting~10 mins

@pytest.mark.parametrize decorator - 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 function with two values for x.

PyTest
import pytest

@pytest.mark.parametrize('x', [[1]])
def test_example(x):
    assert x > 0
Drag options to blanks, or click blank then click option'
A1 2
B1, 2
C(1, 2)
D'1, 2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using space instead of comma to separate values
Passing a tuple instead of a list
Passing a string instead of a list
2fill in blank
medium

Complete the code to parametrize the test function with two parameters: x and y.

PyTest
import pytest

@pytest.mark.parametrize([1], [(1, 2), (3, 4)])
def test_sum(x, y):
    assert x + y > 0
Drag options to blanks, or click blank then click option'
A'(x, y)'
B['x', 'y']
C'x, y'
D('x', 'y')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing parameter names as a list instead of a string
Using parentheses instead of quotes
Including spaces inside the string incorrectly
3fill in blank
hard

Fix the error in the parametrize decorator to correctly test multiple sets of inputs.

PyTest
import pytest

@pytest.mark.parametrize('x, y', [1])
def test_multiply(x, y):
    assert x * y >= 0
Drag options to blanks, or click blank then click option'
A[(1, 2), (3,)]
B[1, 2, 3, 4]
C[(1, 2), 3, 4]
D[(1, 2), (3, 4)]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a flat list instead of list of tuples
Tuples with missing elements
Mixing tuples and single values
4fill in blank
hard

Fill both blanks to parametrize the test with three sets of inputs and check the sum.

PyTest
import pytest

@pytest.mark.parametrize([1], [2])
def test_sum(x, y):
    assert x + y == 3
Drag options to blanks, or click blank then click option'
A'x, y'
B[(1, 2), (2, 1), (0, 3)]
C[(1, 2), (2, 2), (0, 3)]
D'x,y'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter string format
Using tuples with wrong sums
Using lists instead of tuples for values
5fill in blank
hard

Fill all three blanks to parametrize the test with parameters a, b and expected, and check the multiplication result.

PyTest
import pytest

@pytest.mark.parametrize([1], [2])
def test_multiply(a, b, expected):
    assert a * b == [3]
Drag options to blanks, or click blank then click option'
A'a, b, expected'
B[(2, 3, 6), (4, 5, 20), (1, 0, 0)]
Cexpected
D'a, b'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching parameter names and values
Using wrong variable in assertion
Incorrect tuple lengths in values