I build a test suite for a program that runs a lot of SQL statements with now() against a sqlite data base. I would like to mock the sqlite clock --- to test behaviour that is designed to take several days within one second. I do not want to touch the system clock.
Is this possible with sqlite?
Example in Python:
import sqlite3
def mock(*_):
return '1984-01-02 11:22:33'
connection = sqlite3.connect(':memory:')
print(connection.execute('SELECT DATETIME()').fetchone()[0])
connection.create_function('DATETIME', -1, mock)
print(connection.execute('SELECT DATETIME()').fetchone()[0])
Output
2022-03-01 11:23:05
1984-01-02 11:22:33
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With