Skip to content

Commit caefa04

Browse files
committed
fix: delete db after close and get permission
1 parent 5817a29 commit caefa04

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/mem_user/test_mem_user.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,27 @@ class MockSettings:
7070
# Replace the settings import
7171
monkeypatch.setattr("memos.mem_user.user_manager.settings", MockSettings())
7272

73+
manager = None
7374
try:
7475
manager = UserManager()
7576
expected_path = mock_memos_dir / "memos_users.db"
7677
assert manager.db_path == str(expected_path)
7778
assert os.path.exists(expected_path)
7879
finally:
80+
# Close database connections first
81+
if manager:
82+
manager.close()
83+
7984
# Cleanup
80-
expected_path = mock_memos_dir / "memos_users.db"
81-
if os.path.exists(expected_path):
82-
os.remove(expected_path)
83-
if os.path.exists(temp_dir):
84-
os.rmdir(temp_dir)
85+
try:
86+
expected_path = mock_memos_dir / "memos_users.db"
87+
if os.path.exists(expected_path):
88+
os.remove(expected_path)
89+
if os.path.exists(temp_dir):
90+
os.rmdir(temp_dir)
91+
except (OSError, PermissionError):
92+
# On Windows, files might still be locked, ignore cleanup errors
93+
pass
8594

8695

8796
class TestUserOperations:

0 commit comments

Comments
 (0)