pip install responses
python
import responses
import requests
python
@responses.activate
def test_my_api():
responses.add(responses.GET, 'http://api.example.com/endpoint', json={'key': 'value'}, status=200)
response = requests.get('http://api.example.com/endpoint')
assert response.json() == {'key': 'value'}
python test_api.py