0
0
PyTesttesting~10 mins

Why integration tests verify components together 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 import pytest for writing tests.

PyTest
import [1]
Drag options to blanks, or click blank then click option'
Aunittest
Brequests
Cpytest
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like requests or json.
Using unittest instead of pytest for this example.
2fill in blank
medium

Complete the code to define a simple integration test function.

PyTest
def test_components_work_together():
    result = component_a() [1] component_b()
    assert result == 'success'
Drag options to blanks, or click blank then click option'
A+
Band
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical operators like 'and' which don't combine values.
Using multiplication or subtraction which don't apply here.
3fill in blank
hard

Fix the error in the assertion to correctly check the integration result.

PyTest
def test_integration():
    output = integrate_components()
    assert output [1] 'expected output'
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality operator instead of equality.
Using comparison operators like > or < which don't apply.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps component names to their test results if the result is successful.

PyTest
results = {name: result for name, result in components.items() if result [1] 'success' and name [2] 'component_x'}
Drag options to blanks, or click blank then click option'
A==
B!=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up equality and inequality operators.
Using the same operator for both blanks incorrectly.
5fill in blank
hard

Fill all three blanks to create a test that asserts all components return 'ok' status.

PyTest
def test_all_components_ok():
    statuses = {name: status for name, status in check_statuses().items() if status [1] 'ok'}
    assert all(status [2] 'ok' for status in statuses.values()) [3] True
Drag options to blanks, or click blank then click option'
A==
Cis
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' in filters or checks.
Using '==' instead of 'is' for boolean comparison.