Skip to content

Instantly share code, notes, and snippets.

@k-bx
Created June 25, 2013 19:35
Show Gist options
  • Save k-bx/5861641 to your computer and use it in GitHub Desktop.
Save k-bx/5861641 to your computer and use it in GitHub Desktop.
mock example
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()
@leo1361466
Copy link

very thank you !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment