我需要测试一个函数,该函数将在rest_framework.test.APITestCase's assertEqual
中返回带有django
的对象。该对象是这样的:
{
"first_name": "John",
"last_name": "Doe",
"random": some random number
}
如何使用random
键以外的合适结果检查返回的对象?
我的意思是,如果传递了这两个对象,则assertEqual(a, result)
应该返回True
:
a = {
"first_name": "John",
"last_name": "Doe",
"random": 12
}
result = {
"first_name": "John",
"last_name": "Doe",
"random": 24
}
反正在assertEqual
中是否有这种例外情况,或者我必须使用assert
?
您可以创建字典的副本并从此处弹出随机数
a_copy = a.copy().pop("random")
result_copy = result.copy().pop("random")
assertEqual(a_copy, result_copy)