我正尝试第一次使用Python模拟模块(使用pip下载)。我在设置断言时遇到了问题,我将其缩小到这个代码:
class TestUsingMock(unittest.TestCase):
def setUp(self):
self.fake_client = mock.Mock()
def test_mock(self):
self.fake_client.copy = mock.Mock()
self.fake_client.copy("123")
self.fake_client.assert_called_with("123")
if __name__ == "__main__":
unittest.main()这是我得到的错误:
F
======================================================================
FAIL: test_mock (__main__.TestVCSDriver)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./mock_test.py", line 17, in test_mock
self.fake_client.assert_called_with("123")
File "/Library/Python/2.6/site-packages/mock.py", line 859, in assert_called_with
raise AssertionError('Expected call: %s\nNot called' % (expected,))
AssertionError: Expected call: mock('123')
Not called没有断言,一切正常。我究竟做错了什么?