Skip to content

Instantly share code, notes, and snippets.

@okusama27
Last active December 25, 2017 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okusama27/3a95f4e8b1d00fc3d683058998164c83 to your computer and use it in GitHub Desktop.
Save okusama27/3a95f4e8b1d00fc3d683058998164c83 to your computer and use it in GitHub Desktop.
import unittest
from unittest.mock import patch
from sample_method import SampleMethod
class TestSampleMethod(unittest.TestCase):
def setUp(self):
print('setUp')
self.sample = SampleMethod()
def tearDown(self):
print('tearDown')
def test_method_1(self):
print('test_method_1')
with patch('sample_method.SampleMethod.method_1') as mock_method_1:
mock_method_1.return_value = 'AAA'
actual = self.sample.method_1()
print(self.sample.method_1()) # AAA
print(self.sample.method_1()) # method_1
expected = 'AAA'
self.assertEqual(expected, actual)
if __name__ == '__main__':
# unittestを実行
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment