Created
January 5, 2018 17:09
-
-
Save zkan/86ec3e2306f5c286e2e282d262308c73 to your computer and use it in GitHub Desktop.
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 TryMockUsingContextManagerTest(unittest.TestCase): | |
def test_mock_random_twice(self): | |
with patch('__main__.random.randrange') as mock_randrange: | |
with patch('__main__.random.randint') as mock_randint: | |
try_mock_using_context_manager() | |
mock_randint.assert_called_once_with(1, 2) | |
mock_randrange.assert_called_once_with(3, 4) | |
def try_mock_using_context_manager(): | |
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