Complete the code to patch the 'requests.get' method in the test.
from unittest.mock import patch @patch('[1]') def test_fetch_data(mock_get): mock_get.return_value.status_code = 200 assert mock_get.return_value.status_code == 200
The @patch decorator replaces requests.get with a mock object during the test.
Complete the code to patch 'open' function in the 'builtins' module for the test.
from unittest.mock import patch @patch('[1]') def test_file_read(mock_open): mock_open.return_value.read.return_value = 'data' with open('file.txt') as f: content = f.read() assert content == 'data'
To mock the built-in open function, patch builtins.open.
Fix the error in patching the 'datetime.datetime.now' method correctly.
from unittest.mock import patch import datetime @patch('[1]') def test_time(mock_now): mock_now.return_value = datetime.datetime(2020, 1, 1) assert datetime.datetime.now() == datetime.datetime(2020, 1, 1)
You must patch the full path to the method: datetime.datetime.now.
Fill both blanks to patch 'module.Class.method' and set the mock return value.
from unittest.mock import patch @patch('[1]') def test_method(mock_method): mock_method.return_value = [2] result = mock_method() assert result == 42
Patch the full method path and set the return value to 42 to match the assertion.
Fill all three blanks to patch 'package.module.func', set return value, and assert call count.
from unittest.mock import patch @patch('[1]') def test_func(mock_func): mock_func.return_value = [2] mock_func() mock_func() assert mock_func.call_count == [3]
Patch the correct function, set return value to True, and assert it was called twice.