Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_wal_preservation: add debugging for macOS and iOS failures
  • Loading branch information
qris committed Apr 22, 2026
commit 9703cf71c0b2cf4d9cf75dc8442264fd0c874098
14 changes: 11 additions & 3 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,26 +728,34 @@ def test_database_keyword(self):
with contextlib.closing(sqlite.connect(database=":memory:")) as cx:
self.assertEqual(type(cx), sqlite.Connection)

@unittest.skipIf(sys.platform == "darwin", "skipped on macOS")
# @hashbrowncipher skipped this test on mac, don't know why, rerunning to test it
def test_wal_preservation(self):
with tempfile.TemporaryDirectory() as dirname:
path = os.path.join(dirname, "db.sqlite")
with contextlib.closing(sqlite.connect(path)) as cx:
cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, 1)
# Check that it was set successfully:
rc = cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, -1)
assert rc == 1, f"cx.file_control(SQLITE_FCNTL_PERSIST_WAL) failed to set flag"

cu = cx.cursor()
cu.execute("PRAGMA journal_mode = WAL")
result = cu.execute("PRAGMA journal_mode = WAL").fetchall()
assert result == [('wal',)], f"journal_mode could not be set to WAL, is {result}"
cu.execute("CREATE TABLE foo (id int)")
cu.execute("INSERT INTO foo (id) VALUES (1)")
self.assertTrue(os.path.exists(path + "-wal"))
self.assertTrue(os.path.exists(path + "-wal"))

with contextlib.closing(sqlite.connect(path)) as cx:
# Check that we can read the default value when we didn't set it explicitly:
rc = cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, -1)
assert rc == 0, f"SQLITE_FCNTL_PERSIST_WAL should be off by default"

cu = cx.cursor()
self.assertTrue(os.path.exists(path + "-wal"))
cu.execute("INSERT INTO foo (id) VALUES (2)")
self.assertFalse(os.path.exists(path + "-wal"))


def test_file_control_raises(self):
with memory_database() as cx:
with self.assertRaises(sqlite.InternalError):
Expand Down
Loading