明示的に pytest で例外が投げられないのを調べる2022年08月14日 06時30分59秒

例外が投げられるのを確認するテストは多い。それとは逆に、例外が投げられないのをテストする時も少ないが直面する。How to use pytest to check that Error is NOT raised から抜粋し変更。
def test_no_throw():
    try:
        foo(7)
    except:
        pytest.fail("Unexpected exception was thrown.")