I\'m working on a project that involves connecting to a remote server, waiting for a response, and then performing actions based on that response. We catch a couple of diff
Use patch.object
to partially mock a class.
My use case:
import unittest
from unittest import mock
import requests
def test_my_function(self):
response = mock.MagicMock()
response.raise_for_status.side_effect = requests.HTTPError
with mock.patch.object(requests, 'get', return_value=response):
my_function()