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


上一篇:
下一篇:
切换中文