diff --git a/tests/test_find_in_files.py b/tests/test_find_in_files.py index 1f41db5..146caf7 100644 --- a/tests/test_find_in_files.py +++ b/tests/test_find_in_files.py @@ -7,6 +7,7 @@ from pathlib import Path import re import pytest +from PySide6.QtCore import QCoreApplication, QEvent, QEventLoop, QTimer from PySide6.QtWidgets import QApplication from core.file_search import ( @@ -31,6 +32,30 @@ def qapp(): yield app +def _wait_for_signal(signal, already_done, timeout_ms: int = 5000) -> None: + """Wartet ohne pytest-qt, bis ``signal`` im GUI-Thread zugestellt wurde.""" + loop = QEventLoop() + fired = [] + + def _on_signal(*_args): + fired.append(True) + loop.quit() + + signal.connect(_on_signal) + timer = QTimer() + timer.setSingleShot(True) + timer.timeout.connect(loop.quit) + timer.start(timeout_ms) + try: + if not already_done(): + loop.exec() + QCoreApplication.processEvents() + finally: + timer.stop() + signal.disconnect(_on_signal) + assert fired or already_done(), "Signal wurde nicht innerhalb des Timeouts zugestellt" + + def test_compile_search_regex(): # 1. Plain text case-insensitive opts = SearchOptions(query="codebox", case_sensitive=False) @@ -237,10 +262,13 @@ def test_find_in_files_dialog_ui_and_jump(qapp, tmp_path: Path): dlg.search_input.setText("target_keyword") dlg.start_search() - # Wait for background worker to complete - if dlg._worker: - dlg._worker.wait(3000) - qapp.processEvents() + # Auf das zugestellte searchFinished-Signal warten statt den GUI-Thread mit + # QThread.wait() zu blockieren und danach alle gequeuten Signale auf einmal + # per processEvents() abzuarbeiten (nativer Access-Violation-Flake unter + # Windows/Python 3.10, CI-Job 119632528992). + assert dlg._worker is not None + _wait_for_signal(dlg._worker.searchFinished, dlg._worker.isFinished) + dlg._worker.wait(3000) # Verify results in tree assert dlg.results_tree.topLevelItemCount() == 1 @@ -271,6 +299,10 @@ def test_find_in_files_dialog_ui_and_jump(qapp, tmp_path: Path): dlg.close() win.close() + dlg.deleteLater() + win.deleteLater() + QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete) + qapp.processEvents() def test_main_window_show_find_in_files(qapp, tmp_path: Path):