I am writing some doctests in my module.
Relevant code
def foo():
"""
Populates the database with 'VALUES'
>>> import sqlite3
>>> con = sqlite3.connect('test.db')
>>> cur = con.cursor()
>>> cur.execute('select * from users').fetchall()
[('admin', 'Admin', 1, 'admin123'), \
('foo', 'bar', 2, 'foo123'), \
('john', 'doe', 3, 'john123')]
>>>
"""
try:
con = sqlite3.connect('test.db')
cursor = con.cursor()
cursor.executemany("INSERT INTO users VALUES (?, ?, ?, ?)", VALUES)
connection.commit()
connection.close()
except sqlite3.OperationalError as msg:
return msg
Problem that I am facing
$ python -m doctest test_db.py
Failed example:
cur.execute('select * from users').fetchall()
Expected:
[('admin', 'Admin', 1, 'admin123'), ('foo', 'bar', 2, 'foo123'), ('john', 'doe', 3, 'john123')]
Got:
[('admin', 'Admin', 1, 'admin123'), ('foo', 'bar', 2, 'foo123'), ('john', 'doe', 3, 'john123')]
**********************************************************************
References
I looked into these but couldn't find something relevant