diff --git a/src/seedpass_gui/app.py b/src/seedpass_gui/app.py index 0b06153d..414ec3ed 100644 --- a/src/seedpass_gui/app.py +++ b/src/seedpass_gui/app.py @@ -187,7 +187,11 @@ class MainWindow(toga.Window): self.status.text = f"Last sync: {self.last_sync}" def vault_locked(self, *args: object, **kwargs: object) -> None: - self.close() + try: + self.close() + except ValueError: + # Handle case where window is already detached (e.g. in tests) + pass self.controller.main_window = None self.controller.lock_window.show() @@ -391,7 +395,7 @@ class TotpViewerWindow(toga.Window): self.refresh_codes() await asyncio.sleep(1) - def refresh_codes(self) -> None: + def refresh_codes(self, *args: object, **kwargs: object) -> None: self.table.data = [] for idx, label, *_rest in self.entries.list_entries( filter_kinds=[EntryType.TOTP.value] diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 00a179ee..7696800f 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -30,9 +30,15 @@ from seedpass.core.manager import EncryptionMode, PasswordManager from seedpass.core.encryption import EncryptionManager as EncMgr from seedpass.core.pubsub import bus +# Robust check for trio availability +try: + import trio + has_trio = True +except ImportError: + has_trio = False @pytest.fixture( - params=["asyncio"] + (["trio"] if importlib.util.find_spec("trio") else []) + params=["asyncio"] + (["trio"] if has_trio else []) ) def anyio_backend(request): return request.param diff --git a/src/tests/test_gui_features.py b/src/tests/test_gui_features.py index f7f8b63c..7beef10c 100644 --- a/src/tests/test_gui_features.py +++ b/src/tests/test_gui_features.py @@ -108,8 +108,12 @@ def test_totp_viewer_refresh_on_sync(monkeypatch): viewer = seedpass_gui.app.TotpViewerWindow(ctrl, entries) bus.subscribe("sync_finished", viewer.refresh_codes) - # Table rows are Row objects with attribute access - assert viewer.table.data[0].code == "111111" - entries.code = "222222" - bus.publish("sync_finished") - assert viewer.table.data[0].code == "222222" + try: + # Table rows are Row objects with attribute access + assert viewer.table.data[0].code == "111111" + entries.code = "222222" + bus.publish("sync_finished") + assert viewer.table.data[0].code == "222222" + finally: + # Ensure we unsubscribe to prevent test pollution + bus.unsubscribe("sync_finished", viewer.refresh_codes)