I\'m debugging some Python that takes, as input, a list of objects, each with some attributes.
I\'d like to hard-code some test values -- let\'s say, a list of four
This is how I did it:
from mock import patch
import requests
class MockResponse:
def __init__(self, text, status_code):
self.text = text
self.status_code = status_code
class TestSomething(unittest.TestCase):
@patch('requests.get',return_value=MockResponse('the result',200))
def test_some_request(self, *args, **kwargs):
response = requests.get('some.url.com')
assert response.text=='the result'
assert response.status_code=='200'