Skip to content

Instantly share code, notes, and snippets.

@code-sur
Last active December 24, 2015 07:40
Show Gist options
  • Save code-sur/6765644 to your computer and use it in GitHub Desktop.
Save code-sur/6765644 to your computer and use it in GitHub Desktop.
testing patch feature from python mock
HARD_DEPENDENCY = "Hard dependency"
from global_ import HARD_DEPENDENCY
def sut():
return HARD_DEPENDENCY
"""This module runs unittest to try out patch feature from python mock."""
import unittest
from mock import patch
from implementation import sut
from global_ import HARD_DEPENDENCY
class PatchFeatureTest(unittest.TestCase):
def test(self):
self.assertEqual("Hard dependency", HARD_DEPENDENCY)
with patch('implementation.HARD_DEPENDENCY', "mock!"):
self.assertEqual("mock!", sut())
self.assertEqual("Hard dependency", HARD_DEPENDENCY)
self.assertEqual("Hard dependency", HARD_DEPENDENCY)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment