from connection_util import some_engine
class RecommendConversationsUsingOldAPI(BaseResource):
def check_entitlement(self,msg_ids,usr_id, metadata):
conn = some_engine.connect()
some_list = conn.execute(something)
单元测试
@patch('module1.some_engine')
def test_some_method(self, mockEngine):
# some code.....
我可以嘲笑some_engine
@patch('module1.some_engine')
如何为return_value
设置conn.execute()
?
答案 0 :(得分:0)
可以为Mock
返回手动创建的connect()
对象
mock_connection = Mock()
mock_connection.execute.return_value = [1,2,3,4]
mockEngine.connect.return_value = mock_connection