Skip to content

Instantly share code, notes, and snippets.

@echohack
Last active December 14, 2015 03:29
Show Gist options
  • Save echohack/5021130 to your computer and use it in GitHub Desktop.
Save echohack/5021130 to your computer and use it in GitHub Desktop.
import socket
import inject_exception
import requests
from mock import patch
import nose.tools
# ...snippet
def test_api_call():
with patch.object(requests, "get") as get_mock:
with nose.tools.assert_raises(socket.error):
get_mock.side_effect = socket.error
inject_exception.call_api("http://example.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment