Relative Content

Tag Archive for pythonpython-unittest.mock

How to test if an exception is raised using a MagicMock object

import requests import requests.exceptions from requests.exceptions import HTTPError, ConnectionError import unittest from unittest.mock import Mock, MagicMock, patch def request_API_response(query_str : str) -> requests.Response : ”’ get the response from the API, if the status code is not 200, raise an error Parameters query : any – query to control the input response : requests.Response – […]