import pytest


@pytest.fixture(scope="session")
def tk_root():
    """One Tk root for the whole test session, shared by every UI test module: the
    icon library binds its images to the first root, so a second one (or a root torn
    down between tests) invalidates them with 'image "pyimage1" doesn\'t exist'.
    Skips where there is no display, which keeps the suite running on headless CI."""
    tk = pytest.importorskip("tkinter")
    from ccma.ui.theme import load_theme

    try:
        root = tk.Tk()
    except tk.TclError as exc:
        pytest.skip(f"kein Display verfügbar: {exc}")
    root.withdraw()
    load_theme(root, "dark")
    yield root
    root.destroy()
