模拟python数据库查询

2024-10-01 07:19:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过模拟数据库查询进行测试,但收到错误:

Asssertion error:AssertionError: Expected call: execute()
Not called
and create_table() not defined.

我想调用execute(),并使用create_table()返回针对预定义值的断言的响应。在

在应用程序副本在

^{pr2}$

在测试.py在

  import unittest
  from app import *
  from mock import patch

  class Test(unittest.TestCase): 
  def test_create(self):
   with patch("app.g") as mock_g:
     mock_g.db.cursor()
     mock_g.execute.assert_called_with()
     resp = create_table()
     assertEqual(json, '{"Table":"Testmysql is created","Columns": ["id","name","email"]}')

我做错什么了?有人能告诉我怎么修吗


Tags: fromimport数据库appexecute错误createwith
1条回答
网友
1楼 · 发布于 2024-10-01 07:19:48

我相信您需要在关闭光标之前添加更改,否则无法执行。尝试在cursor.close()之前添加cursor.commit()(或代替)。在

相关问题 更多 >