I'm trying to patch sqlite3.Cursor to accept any random kwargs and ignore them.
My attempt is below. Essentially this is trying to patch sqlite3.Cursor with TestCursor which accepts **kwargs, and ignores them.
# in my test code
import sqlite3
from contextlib import contextmanager
from unittest.mock import patch
class TestCursor(sqlite3.Cursor):
def __init__(self, **kwargs):
super().__init__()
@contextmanager
def get_connection():
with patch('sqlite3.Cursor', TestCursor):
conn = sqlite3.connect(':memory:')
# do some database setup
try:
yield conn
finally:
conn.close()
# The function I'm trying to test
def send_query():
with get_connection() as conn:
#offending line
cur = conn.cursor(row_factory='foo')
cur.execute("SELECT * FROM table")
data = cur.fetchall()
return data
send_query()
This gives me
TypeError: 'row_factory' is an invalid keyword argument for this function
Where am I going wrong?
I also tried patching conn directly, but it complains that conn.cursor is read only.