Last active
January 5, 2018 17:07
-
-
Save zkan/bf7e517d3313fd04e6851a27f5ee1c83 to your computer and use it in GitHub Desktop.
Try Mock using Decorator
This file contains hidden or 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 random | |
import unittest | |
from unittest.mock import patch | |
class TryMockUsingDecoratorTest(unittest.TestCase): | |
@patch('__main__.random.randrange') | |
@patch('__main__.random.randint') | |
def test_mock_random_twice(self, mock_randint, mock_randrange): | |
try_mock_using_decorator() | |
mock_randint.assert_called_once_with(1, 2) | |
mock_randrange.assert_called_once_with(3, 4) | |
def try_mock_using_decorator(): | |
random.randint(1, 2) | |
random.randrange(3, 4) | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment