【发布时间】:2016-09-12 22:31:48
【问题描述】:
我有一个测试如下:
import mock
# other test code, test suite class declaration here
@mock.patch("other_file.another_method")
@mock.patch("other_file.open", new=mock.mock_open(read=["First line", "Second line"])
def test_file_open_and_read(self, mock_open_method, mock_another_method):
self.assertTrue(True) # Various assertions.
我收到以下错误:
TypeError: test_file_open_and_read() 只需要 3 个参数(给定 2 个)
我试图指定我希望使用 mock.mock_open 而不是 mock.MagicMock 模拟另一个文件的 __builtin__.open 方法,这是 patch 装饰器的默认行为。我该怎么做?
【问题讨论】:
标签: python unit-testing mocking python-unittest python-mock