diff --git a/tests/unit/sync/test_status.py b/tests/unit/sync/test_status.py index a88d572..c5e9dda 100644 --- a/tests/unit/sync/test_status.py +++ b/tests/unit/sync/test_status.py @@ -34,3 +34,5 @@ def test_legacy_status(status_dict): assert meta2_a.to_status() == meta_a assert meta2_b.to_status() == meta_b assert ident_a == ident_b == ident + + status.close() diff --git a/tests/unit/sync/test_sync.py b/tests/unit/sync/test_sync.py index c3ea627..ea328c1 100644 --- a/tests/unit/sync/test_sync.py +++ b/tests/unit/sync/test_sync.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import contextlib from copy import deepcopy import aiostream @@ -25,13 +26,12 @@ from vdirsyncer.sync.status import SqliteStatus from vdirsyncer.vobject import Item -async def sync(a, b, status, *args, **kwargs): - new_status = SqliteStatus(":memory:") - new_status.load_legacy_status(status) - rv = await _sync(a, b, new_status, *args, **kwargs) - status.clear() - status.update(new_status.to_legacy_status()) - return rv +async def sync(a, b, status, *args, **kwargs) -> None: + with contextlib.closing(SqliteStatus(":memory:")) as new_status: + new_status.load_legacy_status(status) + await _sync(a, b, new_status, *args, **kwargs) + status.clear() + status.update(new_status.to_legacy_status()) def empty_storage(x): diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index 97f48ed..37c27c4 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -232,7 +232,8 @@ def manage_sync_status(base_path: str, pair_name: str, collection_name: str): prepare_status_path(path) status = SqliteStatus(path) - yield status + with contextlib.closing(status): + yield status def save_status( diff --git a/vdirsyncer/sync/status.py b/vdirsyncer/sync/status.py index b5f5246..47f66c8 100644 --- a/vdirsyncer/sync/status.py +++ b/vdirsyncer/sync/status.py @@ -174,9 +174,6 @@ class SqliteStatus(_StatusBase): self._c.close() self._c = None - def __del__(self): - self.close() - def _is_latest_version(self): try: return bool(