Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.