Skip to content

Instantly share code, notes, and snippets.

@dvl
Last active April 8, 2016 22:09
Show Gist options
  • Save dvl/3699cea7265f55dcab37648485decbfa to your computer and use it in GitHub Desktop.
Save dvl/3699cea7265f55dcab37648485decbfa to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import mock
import requests
def make_request():
try:
return requests.get('http://httpbin.org/ip').json()['origin']
except requests.exceptions.ConnectionError:
return '127.0.0.1'
@mock.patch.object(requests, 'get', side_effect=requests.exceptions.ConnectionError('No Internet'))
def test_requests_mock(r_mock):
ip = make_request()
assert ip == '127.0.0.1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment