Skip to content

Instantly share code, notes, and snippets.

@rrees
Created January 12, 2009 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrees/45983 to your computer and use it in GitHub Desktop.
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
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