Created
May 24, 2017 13:41
-
-
Save leopard627/b3979c3e9b51424f0cbfc99c49b26a8a to your computer and use it in GitHub Desktop.
mock_example_python2.7.xx
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
import unittest | |
from os import urandom | |
import mock | |
def simple_urandom(length): | |
return 'f' * length | |
class TestRandom(unittest.TestCase): | |
@mock.patch('__main__.urandom', side_effect=simple_urandom) | |
def test_urandom(self, urandom_function): | |
assert urandom(5) == 'fffff' | |
# from | |
# http://fgimian.github.io/blog/2014/04/10/using-the-python-mock-library-to-fake-regular-functions-during-tests/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment