Skip to content

Instantly share code, notes, and snippets.

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):
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