Created
October 29, 2014 11:50
-
-
Save toast38coza/352f5f535fb6efd2eb4e to your computer and use it in GitHub Desktop.
A strategy for mocking consecutive calls. For example, if you need to test retrying something if you get an Exception on your first pass
This file contains hidden or 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
| @patch.object(TaskHelper, "get_parent") | |
| def test_mocking(self, mock_get_parent): | |
| responses = [Exception('boom'), 'response'] | |
| mock_get_parent.side_effect = lambda *args, **kw: responses.pop(0) | |
| result = TaskHelper.get_parent() | |
| if isinstance(result, Exception): | |
| raise result | |
| result = TaskHelper.get_parent() | |
| print result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment