prole/tests/installer/conftest.py
chrisfu 4ee2b259c9 Checkpoint: rename installer to knoe + harden db build context
- Add build-context helper to copy Docker context safely (ignore runtime data, keep symlinks)

- Update UI and core actions to use ~/.prole/build and shared copy helper

- Add/adjust tests and scripts; introduce knoe ops helpers and update manifests

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-22 01:45:21 -07:00

45 lines
1.6 KiB
Python

"""
Shared fixtures for installer unit tests.
Resets stale tkinter MagicMocks before each test so that tests in
test_screen.py don't hit exhausted side-effect iterators left over from
test_navigation.py (which replaces sys.modules["tkinter"] at module level).
"""
import sys
from pathlib import Path
import pytest
from unittest.mock import MagicMock
# Ensure the repository root is first on sys.path so we import the local
# `installer` package (and not a site-packages name collision).
_REPO_ROOT = Path(__file__).resolve().parents[2]
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
import knoe.screen as _screen_module
@pytest.fixture(autouse=True)
def reset_tkinter_mock():
"""
Before each test, replace any stale tkinter MagicMock with a fresh
instance both in sys.modules and in knoe.screen module namespace,
so TerminalConsole widget calls don't hit exhausted side-effect iterators.
"""
original_screen_tk = getattr(_screen_module, "tk", None)
if isinstance(original_screen_tk, MagicMock):
fresh = MagicMock()
_screen_module.tk = fresh
for mod_name in (
"tkinter",
"tkinter.ttk",
"tkinter.scrolledtext",
"tkinter.messagebox",
):
if mod_name in sys.modules and isinstance(sys.modules[mod_name], MagicMock):
sys.modules[mod_name] = fresh
yield
# Restore original reference so other tests in the suite are unaffected
if isinstance(original_screen_tk, MagicMock):
_screen_module.tk = original_screen_tk