Last active
April 8, 2016 22:09
-
-
Save dvl/3699cea7265f55dcab37648485decbfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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