from pathlib import Path import pytest from nisse_dev.config import REQUIRED from nisse_dev.main import main def test_main_refuses_to_start_without_configuration( monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path, ) -> None: # Clear the real variables rather than swapping os.environ: from_env binds # the environment object as a default argument, so a replacement would be # ignored. And point NISSE_ENV at a file that does not exist, because the # working directory's .env holds live credentials. for name in REQUIRED: monkeypatch.delenv(name, raising=False) monkeypatch.setenv("NISSE_ENV", str(tmp_path / "absent.env")) assert main() == 2 err = capsys.readouterr().err assert "cannot start" in err assert "NISSE_LLM_TOKEN" in err