Skip to content

Instantly share code, notes, and snippets.

@alecklandgraf
Forked from k-bx/main.py
Created October 10, 2013 23:06
Show Gist options
  • Save alecklandgraf/6927026 to your computer and use it in GitHub Desktop.
Save alecklandgraf/6927026 to your computer and use it in GitHub Desktop.
import requests
def do_session_get():
session = requests.session()
return session.get('foo')
import unittest
import mock
from main import do_session_get
class TestDoSessionGet(unittest.TestCase):
@mock.patch('main.requests.session')
def test_should_mock_session_get(self, session_mock):
session_mock.return_value = mock.MagicMock(get=mock.MagicMock(return_value='bar'))
self.assertEqual(do_session_get(), 'bar')
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment