$ tree -I "*pyc"
.
├── src
│ └── hoge.py
└── test
└── hoge_test.py
hoge.py
1 class Hoge:
2 def moge(self):
3 return True
hoge_test.py
1 try:
2 import unittest2 as unittest
3 except (ImportError):
4 import unittest
5 from mock import *
6
7 import sys, os
8 dir_path = os.path.dirname(os.path.abspath(__file__))
9 sys.path.append(dir_path + '/../src')
10 from hoge import Hoge
11
12
13 class TestHoge(unittest.TestCase):
14
15 def setUp(self):
16 self.sut = Hoge()
17
18 def test_hoge_mock(self):
19 self.sut.moge = MagicMock(return_value=False)
20 self.assertFalse(self.sut.moge())
21
22 def test_hoge_raw(self):
23 self.assertTrue(self.sut.moge())
24
25 if __name__ == '__main__':
26 unittest.main()
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
Recommended Posts