rrees (owner)

Revisions

gist: 45983 Download_button fork
public
Description:
Example of how to use Mock to check interactions with the Random module
Public Clone URL: git://gist.github.com/45983.git
Embed All Files: show embed
MockRandomExample.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
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')