Skip to content

Commit 5dd307e

Browse files
committed
try to fix flaky test
1 parent 537b31e commit 5dd307e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/test_imagecache.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,24 @@ def test_cleanup_queue_tracking_empty():
258258
@pytest.mark.asyncio
259259
async def test_get_next_dlset_empty_database(bootstrap):
260260
''' test get_next_dlset with empty database '''
261+
import contextlib
262+
import sqlite3
263+
261264
config = bootstrap
262265
dbdir = config.testdir.joinpath('imagecache')
263266
dbdir.mkdir()
264267

265268
imagecache = nowplaying.imagecache.ImageCache(cachedir=dbdir)
266-
result = imagecache.get_next_dlset()
267-
268-
assert result is None or result == []
269+
try:
270+
result = imagecache.get_next_dlset()
271+
assert result is None or result == []
272+
finally:
273+
# Clean up SQLite WAL files to prevent flaky test failures
274+
if imagecache.databasefile.exists():
275+
with contextlib.suppress(Exception):
276+
with sqlite3.connect(imagecache.databasefile, timeout=5) as conn:
277+
conn.execute("PRAGMA wal_checkpoint(TRUNCATE)")
278+
conn.execute("PRAGMA journal_mode=DELETE")
269279

270280

271281
@pytest.mark.asyncio

0 commit comments

Comments
 (0)