from __future__ import annotations from typing import Any import pytest from doctor_workstation import __main__ as entrypoint def test_smoke_entrypoint_returns_nonzero_instead_of_opening_crash_dialog( monkeypatch: Any, capsys: Any, ) -> None: def fail_startup() -> int: raise RuntimeError("startup failed") monkeypatch.setattr(entrypoint, "main", fail_startup) monkeypatch.setenv("DOCTOR_SMOKE_TEST", "1") assert entrypoint._run() == 1 assert "RuntimeError: startup failed" in capsys.readouterr().err def test_normal_entrypoint_preserves_startup_exception(monkeypatch: Any) -> None: def fail_startup() -> int: raise RuntimeError("startup failed") monkeypatch.setattr(entrypoint, "main", fail_startup) monkeypatch.delenv("DOCTOR_SMOKE_TEST", raising=False) monkeypatch.setattr(entrypoint.sys, "argv", ["doctor-workstation"]) with pytest.raises(RuntimeError, match="startup failed"): entrypoint._run()