0
0
PyTesttesting~10 mins

Multiple parameters 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 mark the test function to run with multiple values for parameter 'x'.

PyTest
import pytest

@pytest.mark.parametrize('x', [1])
def test_is_positive(x):
    assert x > 0
Drag options to blanks, or click blank then click option'
A{1, 2, 3}
B(1, 2, 3)
C[1, 2, 3]
D'1, 2, 3'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a list for parameter values.
Using curly braces which create a set, not a list.
2fill in blank
medium

Complete the code to parametrize two parameters 'a' and 'b' with pairs of values.

PyTest
import pytest

@pytest.mark.parametrize('[1]', [(1, 2), (3, 4)])
def test_sum(a, b):
    assert a + b > 0
Drag options to blanks, or click blank then click option'
A'a; b'
B'a b'
C'(a, b)'
D'a, b'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces without commas between parameter names.
Including parentheses or semicolons in the parameter string.
3fill in blank
hard

Fix the error in the parametrize decorator to correctly pass multiple parameter sets.

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, 4]
B[(1, 2), (3, 4)]
C[(1, 2), (3,)]
D[(1, 2), 3, 4]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list with mixed tuples and integers.
Passing tuples with wrong number of elements.
4fill in blank
hard

Fill both blanks to parametrize a test with parameters 'name' and 'age' and two sets of values.

PyTest
import pytest

@pytest.mark.parametrize([1], [2])
def test_person(name, age):
    assert isinstance(name, str) and age > 0
Drag options to blanks, or click blank then click option'
A'name, age'
B'age, name'
C[('Alice', 30), ('Bob', 25)]
D[('Alice', 30), ('Bob', '25')]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parameter names order without changing values accordingly.
Using a string instead of a list of tuples for values.
5fill in blank
hard

Fill all three blanks to parametrize a test with parameters 'x', 'y', 'expected' and three test cases.

PyTest
import pytest

@pytest.mark.parametrize([1], [2])
def test_add(x, y, expected):
    assert x + y == [3]
Drag options to blanks, or click blank then click option'
A'x, y, expected'
B[ (1, 2, 3), (4, 5, 9), (0, 0, 0) ]
Cexpected
Dx + y
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'x + y' in the assertion instead of 'expected'.
Passing incorrect parameter names or values.