chore(test): Centralize app_instance and mock_app fixtures in conftest.py
This commit is contained in:
@@ -4,6 +4,13 @@ This file tracks all major tracks for the project. Each track has its own detail
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Current Tracks
|
||||||
|
|
||||||
|
- [~] **Track: Tech Debt & Test Discipline Cleanup**
|
||||||
|
*Link: [./tracks/tech_debt_and_test_cleanup_20260302/](./tracks/tech_debt_and_test_cleanup_20260302/)*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Completed / Archived
|
## Completed / Archived
|
||||||
|
|
||||||
- [x] **Track: Conductor Workflow Improvements**
|
- [x] **Track: Conductor Workflow Improvements**
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Architecture reference: [docs/guide_architecture.md](../../../docs/guide_archite
|
|||||||
## Phase 1: Test Suite Deduplication and Centralization
|
## Phase 1: Test Suite Deduplication and Centralization
|
||||||
Focus: Move `app_instance` and `mock_app` to `tests/conftest.py` and remove them from individual test files.
|
Focus: Move `app_instance` and `mock_app` to `tests/conftest.py` and remove them from individual test files.
|
||||||
|
|
||||||
- [ ] Task 1.1: Add `app_instance` and `mock_app` fixtures to `tests/conftest.py`. Ensure they properly yield the App instance and tear down.
|
- [~] Task 1.1: Add `app_instance` and `mock_app` fixtures to `tests/conftest.py`. Ensure they properly yield the App instance and tear down.
|
||||||
- [ ] Task 1.2: Remove local `app_instance` and `mock_app` fixtures from all 13 identified test files. (Tier 3 Worker string replacement / rewrite).
|
- [ ] Task 1.2: Remove local `app_instance` and `mock_app` fixtures from all 13 identified test files. (Tier 3 Worker string replacement / rewrite).
|
||||||
- [ ] Task 1.3: Delete `tests/test_ast_parser_curated.py` if its contents are fully duplicated in `test_ast_parser.py`, or merge any missing tests.
|
- [ ] Task 1.3: Delete `tests/test_ast_parser_curated.py` if its contents are fully duplicated in `test_ast_parser.py`, or merge any missing tests.
|
||||||
- [ ] Task 1.4: Run the test suite (`pytest`) to ensure no fixture resolution errors.
|
- [ ] Task 1.4: Run the test suite (`pytest`) to ensure no fixture resolution errors.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[ai]
|
[ai]
|
||||||
provider = "gemini_cli"
|
provider = "gemini_cli"
|
||||||
model = "gemini-2.0-flash"
|
model = "gemini-2.5-flash-lite"
|
||||||
temperature = 0.0
|
temperature = 0.0
|
||||||
max_tokens = 8192
|
max_tokens = 8192
|
||||||
history_trunc_limit = 8000
|
history_trunc_limit = 8000
|
||||||
@@ -15,7 +15,7 @@ paths = [
|
|||||||
"C:\\projects\\manual_slop\\tests\\artifacts\\temp_livetoolssim.toml",
|
"C:\\projects\\manual_slop\\tests\\artifacts\\temp_livetoolssim.toml",
|
||||||
"C:\\projects\\manual_slop\\tests\\artifacts\\temp_liveexecutionsim.toml",
|
"C:\\projects\\manual_slop\\tests\\artifacts\\temp_liveexecutionsim.toml",
|
||||||
]
|
]
|
||||||
active = "C:\\projects\\manual_slop\\tests\\artifacts\\temp_project.toml"
|
active = "C:\\projects\\manual_slop\\tests\\artifacts\\temp_liveexecutionsim.toml"
|
||||||
|
|
||||||
[gui.show_windows]
|
[gui.show_windows]
|
||||||
"Context Hub" = true
|
"Context Hub" = true
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ active = "main"
|
|||||||
|
|
||||||
[discussions.main]
|
[discussions.main]
|
||||||
git_commit = ""
|
git_commit = ""
|
||||||
last_updated = "2026-03-02T19:29:42"
|
last_updated = "2026-03-02T19:55:24"
|
||||||
history = []
|
history = []
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ import sys
|
|||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Generator, Any
|
from typing import Generator, Any
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
# Ensure project root is in path
|
# Ensure project root is in path
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||||
|
|
||||||
import ai_client
|
import ai_client
|
||||||
|
from gui_2 import App
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def reset_ai_client() -> Generator[None, None, None]:
|
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")
|
ai_client.set_provider("gemini", "gemini-2.5-flash-lite")
|
||||||
yield
|
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:
|
class VerificationLogger:
|
||||||
"""High-signal reporting for automated tests, inspired by Unreal Engine's diagnostic style."""
|
"""High-signal reporting for automated tests, inspired by Unreal Engine's diagnostic style."""
|
||||||
def __init__(self, test_name: str, script_name: str):
|
def __init__(self, test_name: str, script_name: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user