How can I mock sqlite3.Cursor

后端 未结 3 1212
你的背包
你的背包 2021-02-14 12:06

I\'ve been pulling my hair out trying to figure out how to mock the sqlite3.Cursor class specifically the fetchall method.

Consider the followi

3条回答
  •  有刺的猬
    2021-02-14 12:51

    I have found a way to mock sqlite3.Cursor in my tests:

    cursor = MagicMock(Cursor)
    cursor.fetchall.return_value = [{'column1': 'hello', 'column2': 'world'}]
    

    I am pretty new in python but this is how I do it in Java.

提交回复
热议问题