【发布时间】:2020-08-16 19:31:11
【问题描述】:
我正在尝试测试返回字典的函数。我收到错误 AttributeError: 'dict' object has no attribute 'content_type'。如何测试响应是否是字典?
def response_get(url):
try:
response = requests.get(url)
except requests.exceptions.RequestException as e:
raise SystemExit(e)
data = response.json()
return data
def test_response_get(self):
response = response_get('https://ghibliapi.herokuapp.com/films/58611129-2dbc-4a81-a72f-77ddfc1b1b49')
self.assertEqual(response.content_type, 'application/dict')
【问题讨论】:
标签: python unit-testing python-unittest