我在一个类中有两个以下函数,我需要模拟数据库连接和游标结果。cx_Oracle.connect 成功修补它按预期工作。但是游标、callfunc、fetch_all 不会被模拟。知道什么是正确的语法吗?
class dbconnect:
def db_connect(self, connection_details):
connection = cx_Oracle.connect(user_name,pwd,<connection_string>)
return connection
def execute_function(self, sqlFunction, args):
cursor = self.connection.cursor()
res=cursor.callfunc(sqlFunction, cursor.var(cx_Oracle.CURSOR), args)
results = {'headers' : [x[0] for x in res.description],
'data': res.fetchall()
}
cursor.close()
return results
我的模拟代码
with mock.patch('dbconnect.cx_Oracle.connect') as mockOracle:
result_set = {}
mockOracle.cursor.callfunc.fetch_all = result_set
叮当猫咪
相关分类