HTTPリクエストの結果によって変わる振る舞いをテスト 以下は外部のAPIサーバの死活チェックをする関数です。 例外(Timeout, ConnectionError)もしくはステータスコードが200以外の場合はFalse、ステータスコードが200の場合はTrueを返します。 import requests def is_alive_api(): try: response = requests.get('https://example.com/api', timeout=10) except Timeout: return False except ConnectionError: return False if response.status_code != 200: return False return True この関数でテストしたいのは、requests.getの結果によってそ