Created
January 12, 2009 12:37
-
-
Save rrees/45983 to your computer and use it in GitHub Desktop.
Example of how to use Mock to check interactions with the Random module
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
from mock import Mock, patch_object | |
import random | |
mock = Mock() | |
class MyTest(unittest.TestCase): | |
@patch_object(random, 'shuffle', mock) | |
def test_shuffling(self): | |
thing_that_should_shuffle() | |
self.assertTrue(mock.called, 'Shuffle not called') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment