{"width":"100%","author_name":"cookie-box","blog_title":"\u30af\u30c3\u30ad\u30fc\u306e\u65e5\u8a18","blog_url":"https://cookie-box.hatenablog.com/","url":"https://cookie-box.hatenablog.com/entry/2021/10/04/235844","provider_url":"https://hatena.blog","type":"rich","description":"pytest \u3067\u30c6\u30b9\u30c8\u3092\u3059\u308b\u3068\u304d monkeypatch \u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u3084\u74b0\u5883\u5909\u6570\u3092\u30e2\u30c3\u30af\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u4e00\u6628\u65e5\u306e\u8a18\u4e8b\u306e\u3088\u3046\u306b pytest \u304c\u5229\u7528\u53ef\u80fd\u306a pipenv \u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b\u3068\u4ee5\u4e0b\u306e\uff08\u7121\u610f\u5473\u306a\uff09\u30c6\u30b9\u30c8\u304c\u5b9f\u884c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002 import os def test_fuga(monkeypatch): monkeypatch.setenv(\"USER\", \"TestingUser\") assert os.environ[\"USER\"] == \"TestingUser\" $ pipenv run pytest test_hoge.py \u306a\u306e\u3067 pytest \u3068\u3044\u3046\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u300cmo\u2026","image_url":null,"provider_name":"Hatena Blog","title":"\u96d1\u8a18\uff1a pytest \u306e monkeypatch \u306e\u8a71","categories":["\u96d1\u8a18"],"author_url":"https://blog.hatena.ne.jp/cookie-box/","height":"190","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fcookie-box.hatenablog.com%2Fentry%2F2021%2F10%2F04%2F235844\" title=\"\u96d1\u8a18\uff1a pytest \u306e monkeypatch \u306e\u8a71 - \u30af\u30c3\u30ad\u30fc\u306e\u65e5\u8a18\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","version":"1.0","published":"2021-10-04 23:58:44"}