0
0
PyTesttesting~10 mins

Single parameter 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 a single value.

PyTest
import pytest

@pytest.mark.parametrize('number', [[1]])
def test_is_positive(number):
    assert number > 0
Drag options to blanks, or click blank then click option'
A-3
B0
C5
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers which cause the test to fail.
Forgetting to put the parameter inside a list.
2fill in blank
medium

Complete the code to parametrize the test with multiple values using a single parameter.

PyTest
import pytest

@pytest.mark.parametrize('value', [1, 2, [1]])
def test_is_integer(value):
    assert isinstance(value, int)
Drag options to blanks, or click blank then click option'
A3.5
BNone
C'4'
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a float or string instead of an integer.
Not including the parameter inside the list.
3fill in blank
hard

Fix the error in the code by completing the parameter list correctly.

PyTest
import pytest

@pytest.mark.parametrize('item', [1])
def test_not_none(item):
    assert item is not None
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B[None, 1, 2]
C1, 2, 3
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a tuple instead of a list.
Including None which causes the test to fail.
4fill in blank
hard

Fill both blanks to parametrize the test with a single parameter and check for even numbers.

PyTest
import pytest

@pytest.mark.parametrize('[1]', [2, 4, 6, 8])
def test_is_even([2]):
    assert [2] % 2 == 0
Drag options to blanks, or click blank then click option'
Anum
Bnumber
Cvalue
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in the decorator and function argument.
Using names that do not match the parameter list.
5fill in blank
hard

Fill all three blanks to parametrize the test with a single parameter and assert it is a string.

PyTest
import pytest

@pytest.mark.parametrize('[1]', ['apple', 'banana', 'cherry'])
def test_is_string([2]):
    assert isinstance([3], str)
Drag options to blanks, or click blank then click option'
Afruit
Bitem
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in the decorator and function argument.
Mismatching the variable name in the assertion.