chore(test): Centralize app_instance and mock_app fixtures in conftest.py

This commit is contained in:
2026-03-02 20:54:25 -05:00
parent c22f024d1f
commit 35822aab08
5 changed files with 50 additions and 4 deletions

View File

@@ -8,11 +8,13 @@ import sys
import datetime
from pathlib import Path
from typing import Generator, Any
from unittest.mock import patch, MagicMock
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import ai_client
from gui_2 import App
@pytest.fixture(autouse=True)
def reset_ai_client() -> Generator[None, None, None]:
@@ -22,6 +24,43 @@ def reset_ai_client() -> Generator[None, None, None]:
ai_client.set_provider("gemini", "gemini-2.5-flash-lite")
yield
@pytest.fixture
def app_instance() -> Generator[App, None, None]:
"""
Centralized App instance with all external side effects mocked.
Matches the pattern used in test_token_viz.py and test_gui_phase4.py.
"""
with (
patch('gui_2.load_config', return_value={
'ai': {'provider': 'gemini', 'model': 'gemini-2.5-flash-lite'},
'projects': {'paths': [], 'active': ''},
'gui': {'show_windows': {}}
}),
patch('gui_2.save_config'),
patch('gui_2.project_manager'),
patch('gui_2.session_logger'),
patch('gui_2.immapp.run'),
patch.object(App, '_load_active_project'),
patch.object(App, '_fetch_models'),
patch.object(App, '_load_fonts'),
patch.object(App, '_post_init'),
patch.object(App, '_prune_old_logs'),
patch.object(App, '_init_ai_and_hooks')
):
app = App()
yield app
# Cleanup: Ensure asyncio loop is stopped
if hasattr(app, '_loop') and app._loop.is_running():
app._loop.call_soon_threadsafe(app._loop.stop)
@pytest.fixture
def mock_app(app_instance: App) -> App:
"""
Simpler fixture returning a mocked App instance.
Reuses app_instance for automatic cleanup and consistent mocking.
"""
return app_instance
class VerificationLogger:
"""High-signal reporting for automated tests, inspired by Unreal Engine's diagnostic style."""
def __init__(self, test_name: str, script_name: str):