Created
June 25, 2013 19:35
-
-
Save k-bx/5861641 to your computer and use it in GitHub Desktop.
mock example
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
import requests | |
def do_session_get(): | |
session = requests.session() | |
return session.get('foo') |
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
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
very thank you !!!