示例工程 29-testing-pytest
29-testing-pytest/05-monkeypatch-env/test_monkeypatch_env.py
"""test_monkeypatch_env.py"""
from __future__ import annotations
import pytest
from monkeypatch_env import DEFAULT, api_url, main
def test_default(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("API_URL", raising=False)
assert api_url() == DEFAULT
def test_override(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("API_URL", "http://example.test")
assert api_url() == "http://example.test"
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "default: http://localhost:8000" in out