0
0
PyTesttesting~10 mins

Why advanced patterns handle real-world complexity 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 assert that the function returns True.

PyTest
def test_function():
    result = my_function()
    assert result [1] True
Drag options to blanks, or click blank then click option'
A!=
B==
C=
Dis not
Attempts:
3 left
💡 Hint
Common Mistakes
Using single = instead of == in assert
Using != instead of ==
2fill in blank
medium

Complete the code to skip the test when the condition is True.

PyTest
@pytest.mark.skipif([1], reason="Not supported")
def test_feature():
    assert feature()
Drag options to blanks, or click blank then click option'
ATrue
B0
CNone
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using False so test never skips
Using None which is not a boolean
3fill in blank
hard

Fix the error in the fixture definition to return a value.

PyTest
@pytest.fixture
def sample_data():
    data = {'key': 'value'}
    [1] data
Drag options to blanks, or click blank then click option'
Apass
Byield
Cprint
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return
Using pass which returns None
4fill in blank
hard

Fill both blanks to parametrize the test with two values.

PyTest
@pytest.mark.parametrize("input,expected", [
    ([1], [2]),
])
def test_double(input, expected):
    assert double(input) == expected
Drag options to blanks, or click blank then click option'
A2
B4
C3
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping input and expected values
Using wrong numbers that don't match doubling
5fill in blank
hard

Fill all three blanks to create a test that checks if a list contains an item.

PyTest
def test_contains():
    items = [[1], [2], [3]]
    assert 3 in items
Drag options to blanks, or click blank then click option'
A1
B3
C5
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Not including 3 in the list
Using non-integer values