Complete the code to import the mocking tool.
from unittest.mock import [1]
The patch function is used to replace parts of your system under test with mock objects.
Complete the code to mock the requests.get method in the test.
@patch('[1]') def test_fetch_data(mock_get): mock_get.return_value.status_code = 200 assert fetch_data() == 'Success'
We mock requests.get because fetch_data calls it to get data from the internet.
Fix the error in the test by completing the mock patch target correctly.
@patch('[1]') def test_process_data(mock_func): mock_func.return_value = 42 result = process_data() assert result == 42
The patch target must be the name used in the module under test, not the global function name.
Fill both blanks to mock a database call and check the return value.
@patch('[1]') def test_get_user(mock_db_call): mock_db_call.return_value = [2] user = get_user(1) assert user == {'id': 1, 'name': 'Alice'}
We mock database.fetch_user to return the expected user dictionary for the test.
Fill all three blanks to mock a service call, set its return value, and assert the call count.
@patch('[1]') def test_service_call(mock_service): mock_service.return_value = [2] result = call_service() mock_service.[3]() assert result == 'OK'
assert_called_once_with without arguments when the call has none.We patch services.api_call, set its return to 'OK', and check it was called once.