dodil/erp-platform

tests/test_livecheck_finish.py

"""A live check whose step crashes must not report success (finish() runs in a `finally:` that raises SystemExit)."""
from erp_platform import livecheck


def test_a_crash_in_flight_fails_the_run(monkeypatch, capsys):
    monkeypatch.setattr(livecheck, "drop_all", lambda tables: [])
    monkeypatch.setattr(livecheck, "_results", [True, True])
    try:
        raise TypeError("boom")
    except TypeError:
        code = livecheck.finish([])
    assert code == 1 and "FAIL the run stopped: TypeError" in capsys.readouterr().out


def test_a_clean_run_still_passes(monkeypatch):
    monkeypatch.setattr(livecheck, "drop_all", lambda tables: [])
    monkeypatch.setattr(livecheck, "_results", [True])
    assert livecheck.finish([]) == 0