@hainingwyx
2018-12-14T17:36:58.000000Z
字数 347
阅读 1308
python
测试
判断是否调用了某一个函数
import unittest
from mock import patch
def a(n):
if n > 10:
b()
def b():
print "test"
class MyTestCase(unittest.TestCase):
@patch('__main__.b')
def test_b_called(self, mock):
a(11)
self.assertTrue(mock.called)
@patch('__main__.b')
def test_b_not_called(self, mock):
a(10)
self.assertFalse(mock.called)
if __name__ == "__main__":
unittest.main()