Last active
December 24, 2015 07:40
-
-
Save code-sur/6765644 to your computer and use it in GitHub Desktop.
testing patch feature from python mock
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
*.pyc |
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
HARD_DEPENDENCY = "Hard dependency" |
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
from global_ import HARD_DEPENDENCY | |
def sut(): | |
return HARD_DEPENDENCY |
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
"""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