pytestで例外をテストする

概要

raiseを使って例外を出力することをテストしたい場合の書き方です。

コード

import pytest

class TestServiceHandler:
    def test_example(self):
        with pytest.raises(KeyError):
            check_request(sample)