我试图通过模拟数据库查询进行测试,但收到错误:
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"]}')
我做错什么了?有人能告诉我怎么修吗
我相信您需要在关闭光标之前添加更改,否则无法执行。尝试在
cursor.close()
之前添加cursor.commit()
(或代替)。在相关问题 更多 >
编程相关推荐