I want to assert that sqlite3's execute method was called in a subclass.
Here's my module.py:
import sqlite3
class foo(object):
def __init__(self):
self.conn = sqlite3.connect("bla.db")
self.cursor = self.conn.cursor()
def table(self):
self.cursor.execute("create table")
class foobar(foo):
def __init__(self):
super().__init__()
def load(self):
return self.table()
Here's my test file:
from module import foobar
@patch("module.sqlite3")
def test_foobar(mock_sqllite3):
foobar().load()
mock_sqllite3.connect().conn().cursor().execute().assert_called_once()
I'm getting an assertion error, but more to the point, I think i am way off in patching this properly
Is it possible to just mock the foo class attribute self.cursor?