以下の内容はhttps://anton0825.hatenablog.com/entry/2017/06/22/000000より取得しました。


pytestでraiseされた例外をテストする

例外が発生するケースのテストをしたい場合は以下のように with pytest.raises を使う。

def test_recursion_depth():
    with pytest.raises(RuntimeError) as excinfo:

        def f():
            f()

        f()
    assert "maximum recursion" in str(excinfo.value)

as excinfoを使うとちゃんと例外の中身もassertできるし、いいね!

参考:

docs.pytest.org




以上の内容はhttps://anton0825.hatenablog.com/entry/2017/06/22/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14