1
我有以下file1.py其中有代碼。 我試圖創建模擬測試,測試run_q()
蟒蛇模擬爲mysql
file1.py
def exec_mysql(query):
mysql_conn = MySqlActions(..)
..
cur.execute(query)
mysql_conn.commit()
mysql_conn.close()
def run_q():
qa = "delete from table where dts = '%s'" % val
exec_mysql(qa)
下面是模擬代碼。不知道如何提供run_q()
方法的模擬。這是展示它的正確方法嗎?
test_file1.py
import mock
@mock.patch('file1.exec_mysql')
def test_run(mysql_mock)
run_q = mock.Mock()
query = "delete from table where dts = '2015-01-01'"
mysql_mock.assert_called_with(query)